Important: Please read the Qt Code of Conduct -

Drop Event without Subclass

  • Hi guys,

    i am creating a desktop application and i am struggling with QDropEvent.
    I have a QDialog in my application containing 2 QListViews.
    One list view is filled with a String List.
    The task is to choose text from this first ListView and Drag it into the second one.
    This is working fine.
    But i want to have an event fired everytime some String is dropped into the second ListView.

    The solution that i know about is to subclass QListView and create a dropEvent there.
    What i want to do is to not have to subclass QListView, i found out it is possible to catch events by using the Event filter and checking the event that happened.
    Problem is: i never get a Drop event

    Here the relevant code:

    class test : public QDialog
    bool eventFilter(QObject *watched, QEvent *event);


    QListView *left = new QListView(this);
    //same for the second one, just AcceptDrops = true and DragEnabled = false
    bool test:eventFilter(QObject *watched, QEvent *event)
    if(event->type() == QEvent::Drop)
    qDebug()<<"Say hello from Drop";
    return true;
    retrun QObject::eventFilter(watched,event);

    Any Ideas how to fix this or how to make it work without using the event filter are welcome
    Thanks guys!

    P.S: if you need more information just ask i will provide more if needed

  • Lifetime Qt Champion

    Please take a look at the drag and drop documentation here:

  • Lifetime Qt Champion

    Please be advised that the Views have a viewport object
    and in most cases the events goes to it and not the
    actual *View class. So you might need eventfilter on that instead.

    its accessible via ui->ViewX->viewport()

Log in to reply