[PyQt] Model/View, QTreeView, drag/drop and arbitrary objects
Phil Thompson
phil at riverbankcomputing.com
Tue Mar 24 08:41:06 GMT 2009
On Tue, 24 Mar 2009 11:44:41 +1000, Scott Ballard <scott at scottballard.net>
wrote:
> Hi,
>
> I'm trying to put together a QTreeView using the Model/View programming
> but using either the Python Object class or QObject class as the data.
> It seems that neither can be passed around as MIME/QDataStream data for
> the drag and drop functionality. This looks the be a limitation of the
> PyQt implementation and not of Qt itself. Would be great if the
> documentation explicitly mentioned that they didn't implement
> Q_DECLARE_METATYPE() functionality under QMetaType instead having dead
> links to the method.
>
> The current implementation seems to only support a small subset of PyQt
> classes (QStringList and a couple others) These are no good for handling
> objects with a lot of custom attributes.
>
> I'm wondering if anyone has successfully done this before and what the
> trick is? Do you have any example code? There was mention of supporting
> arbitrary Python objects and QDataStream in the PyQt roadmap but no
> mention of when it might be completed. I understand that it won't be
> included in PyQT 4.5.
>
> I really hope that I am overlooking something as my application hinges
> around this. The model/view programming seems great for simple stuff but
> falls apart quickly for more high level uses. Someone must have figured
> this out before!?
The following may help...
https://svn.enthought.com/enthought/browser/TraitsBackendQt/trunk/enthought/traits/ui/qt4/clipboard.py
...which shows how to define a MIME type for a Python object and put it on
the clipboard.
Phil
More information about the PyQt
mailing list