Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.11.1
-
None
-
macOS 10.11.6
Description
This is a macOS specific problem due to the native menubar.
The example program creates a simple window with a menuBar. Because menuBar expects a QWidget parent but all we have is a QWindow we must pass nullptr as parent.
When using the first menu entry to open a modal dialog, the menu entries become inactive as expected. However it is still possible to trigger the second entry by pressing its shortcut (Ctrl+1) - this should not be the case.
The same constellation in a QWidget (QMainWindow) based window works as expected.
#include "mainwindow.h" #include <QDebug> #include <QInputDialog> #include <QAction> #include <QMenuBar> MainWindow::MainWindow(QWindow *parent) : QWindow(parent) { auto openDialogAction = new QAction(this); openDialogAction->setText("Open Dialog"); connect(openDialogAction, &QAction::triggered, this, &MainWindow::onOpenDialogTriggered); auto someAction = new QAction(this); someAction->setText("Action with Shortcut"); someAction->setShortcut(Qt::MetaModifier + Qt::Key_1); connect(someAction, &QAction::triggered, this, &MainWindow::onActionTriggered); auto mb = new QMenuBar(nullptr); auto menu = mb->addMenu("Menu"); menu->addAction(openDialogAction); menu->addAction(someAction); } void MainWindow::onOpenDialogTriggered() { auto r = QInputDialog::getText(nullptr, tr("Bla"), tr("Blub")); qDebug() << r; } void MainWindow::onActionTriggered() { qDebug() << "Triggered"; }