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 :)

Was it helpful?

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:

  1. implement a standalone event filter and make it act upon QEvent::Drop. Install it on your original QListWidget. Return false so that the original dropEvent() handler is called afterwards.

  2. inherit from QListWidget, reimplement dropEvent(evt) and as a last statement, call QListWidget::dropEvent(evt);. Your original behavior will be retained.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top