Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

QGraphicsScene mysteriously always accepts drop events

$
0
0
I am using Drag/drop in a GraphicsView context. Some drops are accepted by specific QGraphicsItems, while others should be handled on the QGraphicsView level. For that purpose I have a subclass of QGraphicsView, with the following dropEvent:         void CTped_GraphicsView::dropEvent( QDropEvent * event )         {                  // Base class should forward the drop event to the scene                 QGraphicsView::dropEvent(event);                                 if (event->isAccepted())                 {                      // If any of my QGraphicsItems accepted the event, I am done                     return;                 }                   // Handle drop event on view level                handleDropEvent(event);         } I get into the drop event, but the call to the base class always results in the event being accepted, no matter whether it was dropped on a QGraphicsItem or not. Debugging into Qt, I found the following code in QGraphicsView::dropEvent:     // Generate a scene event.     QGraphicsSceneDragDropEvent sceneEvent(QEvent::GraphicsSceneDrop);     d->populateSceneDragDropEvent(&sceneEvent, event); It creates a QGraphicsSceneDragDropEvent that it then sends to the QGraphicsScene. But this event is already accepted, before it is ever sent to the QGraphicsScene! If the QGraphicsScene then does not find a QGraphicsItem to send it to, the event stays accepted, and my QGraphicsView assumes the event was already handled. Does anyone have an idea why the created QGraphicsSceneDragDropEvent is accepted by default? Edit: To better formulate the question… I know why the event is accepted. Since it uses a default-constructed QEvent, and since a default-constructed QEvent is accepted, the event is accepted as it is created. The question then is, does it make any sense for the event to be accepted even though no-one handled it?

Viewing all articles
Browse latest Browse all 13965

Trending Articles