[Qt-interest] [SOLVED][4.5] QGraphicsView does not propagate drag & drop events
Andre Somers
andre at familiesomers.nl
Wed Jul 29 14:01:57 CEST 2009
André Somers wrote:
>
> Hi,
>
>
>
> I am trying to implement a QGraphicsView-based visualization that
> requires some drag and drop. While dropping objects on the scene works
> nicely, I am having trouble implementing dragging one GraphicsViewItem
> onto another. The drag operation starts, but there does seem to be any
> drag & drop events happening in my graphic items. I have called
> setAcceptDrops(true) on the graphics items that should accept drops,
> but that does not seem to help.
>
> I am not sure if it is relevant, but the items I am dragging are child
> items of items that have the QGraphicsItem::ItemIsMovable flag set.
>
>
>
> I have reimplemented all the relevant methods in the item that should
> receive the drop (dragEnterEvent, dragMoveEvent, dragLeaveEvent,
> dropEvent) but qDebug() statements show that they are not called. Is
> there something I am overlooking?
>
>
>
> Thanks!
>
>
>
> André
>
>
>
OK, I have managed to solve the issue myself. For future reference, I am
posting the solution.
The key issue was the fact that I was trying to implement drag and drop
on both the scene, as well as on some items. The problem was in a faulty
implementation of the dragging handles of the scene. While these would
work fine for their own purpose, they would basically eat the event if
it did not suit them. I was setting the event to accepted or rejected,
and just returned from the function.
This caused the events not to be propagated down to the QGraphicItems
anymore. The fix was not too complicated: in all re-implemented
drag/drop handlers in my scene, I called the base implementation if the
reimplemented handler itself does not accept the event. This made the
event propagate down to the items on the scene properly, and everything
now works properly.
André
More information about the Qt-interest-old
mailing list