Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.12.3
-
None
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:
- Start the application below.
- Click on the tree view item and drag it around.
- While still holding the mouse button during the drag, hold down Ctrl and hit D a couple of times.
- 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(); }