QGraphicsScene mysteriously always accepts drop events

  • 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

                if (event->isAccepted())
                     // If any of my QGraphicsItems accepted the event, I am done
                // Handle drop event on view level

    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?

  • Lifetime Qt Champion


    I think this might be a good question to ask on the interest mailing list, you'll find Qt's developers/maintainers there (this forum is more user oriented)

  • From a user's perspective, I found the following solution to be effective:

    • Subclass QGraphicsScene
    • In QGraphicsScene::dropEvent():


    I used to be on the mailing list. However, I had the impression that the forums here had been intended as a replacement for the mailing list.

  • Lifetime Qt Champion

    AFAIK no, but the forum might be more user friendly especially for new comers.

    Also Qt's dev don't follow this forum (maybe a handful few of them)

  • After some further thought, I have created "QTBUG-33212":https://bugreports.qt-project.org/browse/QTBUG-33212

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.