QListWidget drag and drop
-
Hi
I have a QListWidget that has drag and drop enabled and I am able to drag an item onto it (from another widget) and have it added to the list
My problem is that if I drag an item within the list the item being dragged replaces the item underneath, whereas I want to just change the order.Has anyone got any ideas as to what is happening here
Cheers
-
have a look at this
https://forum.qt.io/topic/1786/qlistwidget-reorder-with-drag-and-drop/3I think setDragDropMode(QAbstractItemView::InternalMove); is the key.
-
have a look at this
https://forum.qt.io/topic/1786/qlistwidget-reorder-with-drag-and-drop/3I think setDragDropMode(QAbstractItemView::InternalMove); is the key.
-
oh, well the name kinda suggested that now you tell me ;)
Sorry, did never try to mix both internal and external drop. But I do understand why you want it.
Maybe you can handle it yourself ? -
@mrjj said:
This class allows to rearrange internally and drop from other list by
changing setDragDropMode on the fly.
For easy use , use the promote feature.
Sorry for the lame name.myhappylist.h
#ifndef MYHAPPYLIST_H #define MYHAPPYLIST_H #include <QListWidget> #include <QDragEnterEvent> class myhappylist : public QListWidget { public: explicit myhappylist(QWidget *parent = 0) : QListWidget(parent) { } ~myhappylist(); protected: void dragEnterEvent(QDragEnterEvent *event); };
myhappylist.cpp
void myhappylist::dragEnterEvent ( QDragEnterEvent *event ) { if ( event->source() != this ) { setDragDropMode ( QAbstractItemView:: DragDrop ); event->accept(); } else { setDragDropMode ( QAbstractItemView::InternalMove ); event->accept(); } } myhappylist::~myhappylist(){}
-
I have the same issue. When i make custom class
Solved by implementing all D&D parent events. (But in any topic two enough)DndListWidget : public QListWidget { void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; // if this two will not be implemented DnD will works not properly void dragMoveEvent(QDragMoveEvent* event) override; void startDrag(Qt::DropActions supportedActions) override; }
@mrjj Thanks for "if ( event->source() != this )" ))