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

REG: QAction shortcut not triggered without ctrl modifier on Mac

XMLWordPrintable

    • macOS
    • 412ec70f14aa0c966d13481a35c498e6c905dec3, 22afbc153628348bc6d4ee0655ea6a6584a13322

      Set QAction shortcut to plain letter "i" and it doesn't trigger on Mac. It works on Qt 4.8 and Qt 5.0.2. Only Mac issue.

      Workaround is to use QShortcut instead of QAction or trigger QAction from QShortcut like example below:

      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QMainWindow mainWindow;
          QMenu* menu = new QMenu("&Zoom",&mainWindow);
      
          QAction* zoomInAction = new QAction("Zoom &in", &mainWindow);
          zoomInAction->setShortcut(QKeySequence("i"));
          QObject::connect(zoomInAction, SIGNAL(triggered()), &mainWindow, SLOT(showMaximized()));
          menu->addAction(zoomInAction);
      
          QAction* zoomOutAction = new QAction("Zoom &Out", &mainWindow);
          zoomOutAction->setShortcut(QKeySequence("o"));
          QObject::connect(zoomOutAction, SIGNAL(triggered()), &mainWindow, SLOT(showNormal()));
          menu->addAction(zoomOutAction);
      
      //// WORKAROUND
      //#ifdef Q_OS_MAC
      //    QObject::connect(new QShortcut(zoomInAction->shortcut(),zoomInAction->parentWidget()),
      //                     SIGNAL(activated()), zoomInAction, SLOT(trigger()));
      //    QObject::connect(new QShortcut(zoomOutAction->shortcut(),zoomOutAction->parentWidget()),
      //                     SIGNAL(activated()), zoomOutAction, SLOT(trigger()));
      //#endif
      
          mainWindow.menuBar()->addMenu(menu);
          mainWindow.show();
          return a.exec();
      }
      

      Could this cause the issue?
      https://bugreports.qt-project.org/browse/QTBUG-30695
      https://codereview.qt-project.org/#change,54652

        1. option_bug.tar.gz
          1.0 kB
        2. QTBUG-38256.zip
          4 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            dedietri Gabriel de Dietrich (drgvond)
            qtcomsupport Qt Support
            Votes:
            7 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes