如何在 Qt 中使用两个键修饰符设置 3 键序列快捷方式?

How to set 3-key sequence shortcut with two key modifiers in Qt?

我一直在尝试将快捷方式设置为 Ctrl + Shift +C

我试过以下方法:

QAction *generalControlAction = new QAction(this);
generalControlAction->setShortcut(QKeySequence("Ctrl+Shift+c"));
connect(generalControlAction, &QAction::triggered, this, &iBexWorkstation::onGeneralConfiguration);

QShortcut *generalControlShortcut = new QShortcut(QKeySequence("Ctrl+Shift+C"), this);
connect(generalControlShortcut, &QShortcut::activated, this, &iBexWorkstation::onGeneralConfiguration);

他们没有工作。当我按下 Ctrl + Shift +C.

时没有触发任何东西

Qt中不能设置两个修饰符的快捷方式吗?

generalControlAction->setShortcut(QKeySequence(Ctrl+Shift+c));

只需将代码中的上述语句更改为

generalControlAction->setShortcut((Ctrl+Shift+C));

这应该可以正常工作。 "C"后面应该是大写的

请参考下面给定的键序列 link http://doc.qt.io/qt-5/qkeysequence.html

我写了一个最小的完整示例。它在我的案例中是如何描述的。可能是,我添加了一些您没有添加的内容。 (这就是为什么 "minimal, complete, verifiable samples" 是首选。)

// standard C++ header:
#include <iostream>

// Qt header:
#include <QAction>
#include <QApplication>
#include <QLabel>
#include <QMainWindow>

using namespace std;

int main(int argc, char **argv)
{
  cout << QT_VERSION_STR << endl;
  // main application
#undef qApp // undef macro qApp out of the way
  QApplication qApp(argc, argv);
  // the short cut
  const char *shortCut = "Ctrl+Shift+Q";
  // setup GUI
  QMainWindow qWin;
  QAction qCmdCtrlShiftQ(&qWin);
  qCmdCtrlShiftQ.setShortcut(QKeySequence(shortCut));
  qWin.addAction(&qCmdCtrlShiftQ); // DON'T FORGET THIS.
  QLabel qLbl(
    QString::fromLatin1("Please, press ")
    + QString::fromLatin1(shortCut));
  qLbl.setAlignment(Qt::AlignCenter);
  qWin.setCentralWidget(&qLbl);
  qWin.show();
  // add signal handlers
  QObject::connect(&qCmdCtrlShiftQ, &QAction::triggered,
    [&qLbl, shortCut](bool) {
    qLbl.setText(
      QString::fromLatin1(shortCut)
      + QString::fromLatin1(" pressed."));
  });
  // run application
  return qApp.exec();
}

我怀疑你没有打电话给QWidget::addAction()。如果我将其注释掉,它在我的程序中也不再起作用。

在 Windows 10(64 位)上用 VS2013 和 Qt 5.6 编译:

此快照是在按 Ctrl+Shift+Q 后制作的。

注:

后来我意识到实际问题是关于 "Ctrl+Shift+C"。可以肯定的是,我检查了它。上面的示例代码也适用于 "Ctrl+Shift+C"。