0

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

hytromo
  • 1,501
  • 2
  • 27
  • 57

2 Answers2

2

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.

Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
  • Thanks both of you, how am I going to distinguish between the listwidget and the treewidget items, while both of them return application/x-qabstractitemmodeldatalist as mime type? – hytromo Sep 12 '12 at 16:53
  • 2
    QDropEvent->source()->inherits("QTreeWidget") – Pavel Zdenek Sep 12 '12 at 19:38
1

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?

Community
  • 1
  • 1
UmNyobe
  • 22,539
  • 9
  • 61
  • 90
  • Thanks both of you, how am I going to distinguish between the listwidget and the treewidget items, while both of them return application/x-qabstractitemmodeldatalist as mime type? – hytromo Sep 12 '12 at 16:52