Unsolved 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 eventHere the relevant code:
myClass.hclass test : public QDialog { Q_OBJECT ... protected: bool eventFilter(QObject *watched, QEvent *event); ...
myClass.c
test:test() { QListView *left = new QListView(this); left->setAcceptDrops(false); left->setDragEnabled(true); left->setDropIndicatorShown(true); left->setEditTriggers(QAbstractItemView::NoEditTriggers); left->setModel(model); left->installEventFilter(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; } else { 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
-
Please take a look at the drag and drop documentation here: http://doc.qt.io/qt-5/dnd.html
-
Hi
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()