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

Shortcut can occasionally get triggered during drag and drop

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.12.3
    • Fix Version/s: None
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      While dragging and dropping, it is possible for QAction to be triggered via shortcut. So far only tested it on Qt 5.4.1 and 5.12.3 since those are the builds we are using for our products. While some products might find it useful to be able to trigger shortcut during drag and drop, I find it more problematic given user can be triggering undo which might cause the QDrag to get destroyed if the undo action result in the parent QWidget getting destroyed which would cause the system to crash. Windows Explorer also seemingly to not support shortcut during drag and drop.

      Repro Steps:

      1. Start the application below.
      2. Click on the tree view item and drag it around.
      3. While still holding the mouse button during the drag, hold down Ctrl and hit D a couple of times.
      4. You should see "Action triggered" getting printed to the console a few times.

      The issue is intermittent, meaning I can hit the Ctrl+D shortcut 10 times and only see the action getting triggered occasionally (i.e. "Action triggered" is printed out less than 10 times).

       

      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QMainWindow* testWindow = new QMainWindow;
          testWindow->resize(500, 500);
          QTreeWidget* tree = new QTreeWidget();
          tree->setAcceptDrops(true);
          tree->setDragEnabled(true);
          tree->setDragDropMode(QAbstractItemView::InternalMove);
          testWindow->setCentralWidget(tree);
      
          QTreeWidgetItem* dad = new QTreeWidgetItem(tree,0);
          dad->setText(0, "Hello");
          QTreeWidgetItem*  child = new QTreeWidgetItem(dad,0);
          child->setText(0, "World");
      
          QMenu* testMenu = testWindow->menuBar()->addMenu("Test");
          QAction* action = testMenu->addAction("Keyboard Shortcut Triggered");
          action->setShortcut(Qt::ControlModifier + Qt::Key_D);
          QObject::connect(action, &QAction::triggered, testWindow, [testWindow]()
          {
              qDebug() << "Action triggered!!";∂
          });
          testWindow->showNormal();
      
          return app.exec();
      }
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            owolff Oliver Wolff
            Reporter:
            thuan_firelight Thuan Seah
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes