I want to extend dropEvent() (QListWidget), should I completely reimplement it?
-
01-07-2021 - |
Question
I have a QListWidget and I have set it to accept drops, the mode to be DragDrop etc and I can move QListWidgetItems all around the place (inside the QListWidget of course).
I like this behavior and I want it to let it as is, but I also want my QListWidget to accept drops from a QTreeWidget as well. If I attempt to reimplement the dropEvent() of my QListWidget then I lose the default behavior.
Is there any way to just extend the current behavior so as to have both drag-drop between listwidget items and drag-drop from the treewidget to the listwidget or I have to completely re-write both behaviors in my dropEvent() reimplementation?
Thanks a lot for any answers :)
Solution
No.
Subclass QListWidget
, reimplement
virtual void QListWidget::dropEvent ( QDropEvent * event )
and explicitly call
QListWidget::dropEvent(event);
whenever you need the default behavior.
How to call a parent class function from derived class function?
OTHER TIPS
Two ways:
implement a standalone event filter and make it act upon
QEvent::Drop
. Install it on your original QListWidget. Return false so that the originaldropEvent()
handler is called afterwards.inherit from
QListWidget
, reimplementdropEvent(evt)
and as a last statement, callQListWidget::dropEvent(evt);
. Your original behavior will be retained.