[PyKDE] PYKDE Drag and drop

Jim Bublitz jbublitz at nwinternet.com
Mon Jun 19 18:53:06 BST 2000

On 18-Jun-00 Boudewijn Rempt wrote:
> On Sun, 18 Jun 2000, Phil Thompson wrote:
>> Jim Bublitz wrote:
>> > 
>> > Two questions/problems with DND:
>> > 
>> > (using PYKDE 0.11/Qt 1.44/KDE 1.2)
>> > 
>> > 2. (This may indicate my unfamiliarity with Python)
>> > If I derive a widget, say from QListView, and want
>> > to multiply inherit QDropSite, how do I do the
>> > QDropSite init (it needs a pointer to the widget
>> > to install the event filter)? I have:
>> > 
>> > class  KFoo (QListView, QDropSite):
>> >      def __init__(self, parent):
>> >           QListView.__init__(self, parent)
>> > 
>> > Do I add:
>> > 
>> > QDropSite.__init__(self, self)  ??
>> > 
>> > Also, it seems to make a difference if I do that
>> > before or after the QListView call. Of course I
>> > can't test this, because (see 1) I'm not getting
>> > any events to test it with.
>> Sorry - you can't do this in Python. Both the QListView and the
>> QDropSite __init__ methods will create separate widgets. The bindings
>> only create wrappers for existing C++ classes - what you are trying to
>> do is to create a new C++ class, which you can't do from Python.
>> If there is no other way of achieving what you want then you will have
>> to create KFoo in C++ and then create a new Python module using SIP to
>> wrapp the KFoo class.
> It should be possible to find a solution in Python. Why not take 
> a leaf out of the visual basic book, and inherit by aggregation?
> Takes a bit more work, but should work like a charm:
> class myClass(QWidget):
>   def__init__(self, args):
>     self.listview=QListView(...)
>     self.dropsite=QDropSite(...)
> Then define all the methods you need and have them call the
> right constituent method.
>   def insertItem(...)
>     self.listview.insertItem(...)

Two very fast responses! Thanks!

I've already tried something similar, except 
making "myClass" a descendant of QListView 
instead of QWidget, and I think there's a 
way to make that work - there's some details 
about receiving the Drag/Drop event msgs
and forwarding them to "myClass" IIRC. Don't 
recall the details, but it seemed doable from 
looking at the Qt code.

The problem I still have (snipped from the 
beginning of this message) is getting  
QDragObject or one of its descendants to work, 
so I can't really try this until that's solved.
I'm still doing some investigation on that, 
and will post again when either I find a fix 
or feel completely stumped again.

I noticed Phil requested in an archived
message to be notified about things that work.
This is part of a fairly large application
that uses a lot of the Qt stuff and some KDE
stuff (and a lot of Python modules) and 
everything else works great - this is the
first real snag I've hit  Even without a 
graphical design tool, this is a superior 
rapid application development environment. 
Thanks for all of your work.


More information about the PyQt mailing list