Qt World Summit: Register Today!

[SOLVED] QQuickWidget doesn't accept drops

  • I'm using a subclass of QQuickWidget and want to make use of drop acceptance functionality that is supposed to work considering it's a QWidget class (and because the docs don't mention anything about it not working).

    Some code:

    // QuickWidget.h

    #include <QQuickWidget>

    class QuickWidget : public QQuickWidget

    QuickWidget(QWidget *parent = 0);
    virtual void dragEnterEvent(QDragEnterEvent *event);


    // QuickWidget.cpp

    // ...

    void QuickWidget::dragEnterEvent(QDragEnterEvent *event)
    if (true)
    // Some code with a breakpoint

    MainWindow code:

        qw = new QuickWidget(this);  // qw is a member of type QuickWidget * defined in the main window header



    Now trying to drag some selected text into the window - nothing happens (the breakpoint doesn't hit).

    Alternatively, replaced the QuickWidget with a Widget (QWidget subclass with the same override of the drag enter code) - drag enter code hits breakpoint as expected.

    Am I correct in saying that setAcceptDrops doesn't work properly for QQuickWidget?

  • Moderators

    The drop happens in the QML scene (add a DropArea in the qml to handle it) so my guess is you would have to pass that to the C++ side manually somehow (don't know QML that well). I don't think QQuickWidget handles this kind of propagation automatically.

  • Drag and drop works fine with QQuickWidget but, as pointed out above, you are supposed to handle it via a DropArea in the Qt Quick scene. Reimplementing dragXxxEvent or dropEvent is futile since QQuickWidget never invokes these.

  • Strange. It is not up to QQuickWidget to "invoke" the event handlers. It should be the other way around: QQuickWidget should be reimplementing the handlers itself in order to handle the events in QML. Appearently, it is not doing that, but probably is reimplementing the generic event handler instead, thereby IMHO breaking the contract of providing the virtual functions in the first place.

    You should be able to check the above by reimplenting the event method, and checking if the d&d related events do pass through there.

    Please file a bug for it.

  • Thank you for your replies.

    Andre - you were right - reimplementing QuickWidget::event() I managed to intercept the drag enter event. This is really what I wanted so I'm changing this to SOLVED and will open a bug as suggested.

    By the way, since the recent spam comments in the forums, I find that I sometimes don't get e-mail notifications for legit comments on my posts. So only seeing this now. Sorry and thank you once again!

  • When you filed your bug, please cross-reference the bugreport and this topic by putting a link to this topic in the bugreport, and then a link to your bugreport in this topic.

Log in to reply