QListWidget reorder with Drag and Drop
-
This works for me:
@
#include <QApplication>
#include <QListWidget>int main(int argc, char **argv)
{
QApplication a(argc, argv);QListWidget lw; for(int i = 1; i < 10; ++i) lw.addItem(new QListWidgetItem(QString("Item %1").arg(i))); lw.setDragDropMode(QAbstractItemView::InternalMove); lw.show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); a.exec();
}
@ -
Strange. It works for me, too. I wonder why my other application doesn't then.
-
Do you use a user interface made with Qt Designer and did you change some of the drag/drop settings there?
-
Do you use QListWidget or QListWidget inherited widget? If you inherit from listWidget and use mouse or drag events and didn't pass event to QListWidget, drag and drop will not work.
-
I made it with Qt Designer and I changed the drag and drop properties a lot, but now I changed them back to just dragDropMode = internalMove and put the others back to default. The selection mode is ExtendedSelection, but I tried the default, too.
-
That should work. I tried this with designer and could move the items in the preview mode (Ctrl-R/Cmd-R). That should work in the real code too, if you do not change other drag/drop settings there too.
-
Even stranger news:
I created a new project, copied and pasted all of the code / widgets, and now its working!
Any ideas why this happened and how to prevent it in the future?
-
Sorry, I do not have any clue what's happening there. Maybe some alien code from outer space? :-)
-
Here is my scenario: You use visual studio. Your code had little error. Complier didn't compile code and ran old executable.
-
Actually, I use Qt Creator.
-
this helped me a lot! thanks
-
helped me too, thanks!
-
Worked for me!
-
The viewMode should be ListMode(default) but not IconMode, even items have icons.