Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Drag-drop with internalmove makes items disappear

    General and Desktop
    3
    3
    1078
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kalas last edited by

      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); // ***
      
          lw.setDragDropMode(QAbstractItemView::InternalMove);
      
          lw.show();
      
          a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
          a.exec();
      }
      

      Here's how this looks for me:
      Imgur

      Any ideas?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        Can you try again with Qt 5.5 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • mrjj
          mrjj Lifetime Qt Champion last edited by

          tried the code with 5.5 and it does work there.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post