Important: Please read the Qt Code of Conduct -

Drag-drop with internalmove makes items disappear

  • Hi,

    I'm trying to make drag and drop inside a treewidget work to be able to move items around. I've managed to make items draggable but when I release the mouse button the item disappears. I've tried the following example from stackoverflow and this has the same issues as my tree widget in Qt 5.4 on Windows 7.

    #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.setDragEnabled(true); // ***
        lw.viewport()->setAcceptDrops(true); // ***
        lw.setDefaultDropAction(Qt::MoveAction); // ***
        lw.setDropIndicatorShown(true); // ***
        a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));

    Here's how this looks for me:

    Any ideas?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you try again with Qt 5.5 ?

  • Lifetime Qt Champion

    tried the code with 5.5 and it does work there.

Log in to reply