Skip to main content

Ralsina.Me — Roberto Alsina's website

Post-facto inheritance

Now, I did­n't ex­pect this to work at al­l!

A QlistView is a sort of tree wid­get, and is drag&­drop en­abled.

The trick is, you have to reim­ple­ment dragOb­jec­t() so it re­turns a drag­gable thingie af­ter you drag some­thing.

But, since I am us­ing de­sign­er to draw the form­s, I have to use a re­al QListView, not a child class.

Co­nun­drum? Cus­tom wid­get in de­sign­er? Not with python!

def myDragObject(self):

re­turn QTextDrag("­some­thing",­self)

self­.tree.__­class__.­dragOb­jec­t=my­DragOb­ject

And that work­s! I know it should work in python, but QListView is im­ple­ment­ed in a C++ mod­ule!

The guys that did PyQt re­al­ly made it well.

Torsten Marel / 2006-04-03 05:35:

Thanks for the demo code. I suspected that such a tweak should exist, but I was not sure _how_ this could be done.

Since it is also possible to use QUriDrag, QImageDrag and so on, implementing simple dNd with applications (I use it to drag "filenames" from a PyQt application to beep-mp) becomes almost trivial



greets


Contents © 2000-2024 Roberto Alsina