Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-70240

Changing widget's parent disables drag and drop

XMLWordPrintable

    • Windows

      In the following example, if you open the list, you can drag and drop the items. If you close it and open again, drag and drop no longer works.

      The problem is because QWidget code recreates the drop site while the Qt::Window flag is off, invoking QWindowsWindow::updateDropSite, which does the wrong thing and calls setDropSiteEnabled(false).

      Related stack overflow thread: https://stackoverflow.com/a/52066150/683905

      #include <QtWidgets>
      
      int main(int argc, char *argv[]) {
         QApplication app(argc, argv);
         QPushButton button("Toggle List");
         QListWidget listWidget;
      
         button.setMinimumSize(320, 200);
         Q_ASSERT(!listWidget.testAttribute(Qt::WA_DeleteOnClose));
         listWidget.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
         listWidget.setDragDropMode(QAbstractItemView::DragDrop);
         listWidget.setDefaultDropAction(Qt::MoveAction);
         for (auto s : {"first", "second", "third"})
              listWidget.addItem(QLatin1String(s));
      
         QObject::connect(&button, &QPushButton::pressed, [&] {
            static bool toggle;
            if ((toggle = !toggle)) {
               listWidget.setParent(&button, listWidget.windowFlags());
               listWidget.show();
            } else {
               listWidget.setParent(nullptr);
               listWidget.close();
            }
         });
      
         button.show();
         return app.exec();
      }
      

        1. qtbug70240.zip
          2 kB
          Friedemann Kleint
        2. qtbug70240_diag.diff
          3 kB
          Friedemann Kleint
        3. qtbug70240_log.txt
          3 kB
          Friedemann Kleint
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kleint Friedemann Kleint
            danprinc danprinc
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes