[PyQt] Re: PyQt4: QGraphicsView/drag&drop problem

Frank Ploss frank.ploss at informatik.uni-hamburg.de
Tue Jun 26 20:40:55 BST 2007


Eriol wrote:

> On Thursday 21 June 2007, Frank Ploss wrote:
>> I'm trying to implement drag and drop with a QGraphicsView.
> 
> Can't you use the default Graphics View framework drag and drop support
> provided for the scene, and for each item?

No, I need better control over the look and position of dragged items.
But ...

> 
> ----8<----------------------------------
> ...
> > ------>8---------------------------------------- 
> 
> If not, consider that (from the doc:
> http://doc.trolltech.com/4.2/graphicsview.html#drag-and-drop):
> 
> To intercept drag and drop events for the scene, you reimplement
> QGraphicsScene::dragEnterEvent() and whichever event handlers your
> particular scene needs, in a QGraphicsItem subclass.

... your repeating of the docs I had already read a dozen times before
pointed me to the fact that I shouldn't catch the drop events in the
*scene* (which doesn't work), but in an *item* (which does work). So the
solution was to create a background QGraphicsRectItem, add it to the scene
and catch and process the drop events there.

Thanks!
Frank

> 
> Items can enable drag and drop support by calling
> QGraphicsItem::setAcceptDrops(). To handle the incoming drag, reimplement
> QGraphicsItem::dragEnterEvent(), QGraphicsItem::dragMoveEvent(),
> QGraphicsItem::dragLeaveEvent(), and QGraphicsItem::dropEvent().
> 
> HTH,
> 




More information about the PyQt mailing list