[PyQt] Drag and Drop when using designer

Andreas Pakulat apaku at gmx.de
Thu Oct 25 10:53:12 BST 2007


On 25.10.07 12:30:20, Jan Ekholm wrote:
> On Thursday 25 October 2007, Andreas Pakulat wrote:
> > On 25.10.07 04:22:39, Nahuel Defossé wrote:
> > > Hi!
> > >
> > > I've made all my gui with designer. I have some List Views there that
> > > need drag and drop funcitonality so I need to add them some methods to
> > > handle the drop events properly, and set the accept drops to True... but
> > > I can't add those methods with setattr, they don't work, it seems I have
> > > to subclass the List Views.
> >
> > I'm not sure if thats really needed, never created itemviews that can do
> > drag and drop. The puzzle example indicates however that you don't need
> > to change the listviews, only the underlying model which needs to
> > provide mimeData and dropMimeData and probably also mimeTypes. Then you
> > just need to enable the drag/drop on the listviews by setting their dnd
> > properties to true.
> 
> At least I couldn't get DnD to work without subclassing and providing 
> something in the dragEnterEvent, dragMoveEvent and dropEvent handlers. But it 
> did work fine when following the docs at:
> 
> 	http://doc.trolltech.com/4.3/dnd.html

Thats mostly for normal QWidget subclasses, the interview classes have
dnd support builtin, based on what the model provides. The puzzle
example demonstrates this pretty well, you have a listview and a normal
qwidget and both have drag and drop capabilities. There's only a
subclass for the QWidget, the listview stays "standard" - only the model
has proper overrides for the drag/drop methods needed.

Andreas

-- 
You have no real enemies.


More information about the PyQt mailing list