Search code examples
qtdrag-and-dropimplementationqlistwidget

I want to extend dropEvent() (QListWidget), should I completely reimplement it?


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?