Onu*_*una 6 c++ qt keyboard-shortcuts c++11 qt5
我一直在尝试将快捷方式设置为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);
Run Code Online (Sandbox Code Playgroud)
他们没有工作.按Ctrl+ Shift+ 时没有触发任何内容C.
在Qt中设置两个修饰符的快捷方式是不可能的吗?
我写了一个最小的、完整的示例。它在我的情况下有效,就像你所描述的那样。可能是,我添加了一些你没有的东西。(这就是为什么“最少、完整、可验证的样本”是首选的原因。)
// 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();
}
Run Code Online (Sandbox Code Playgroud)
我怀疑你没有打电话QWidget::addAction()。如果我将其注释掉,它在我的程序中也不再起作用。
在Windows 10(64位)上使用VS2013和Qt 5.6编译:
此快照是按 Ctrl+Shift+Q 后制作的。
笔记:
后来我意识到实际的问题是关于“Ctrl+Shift+C”。可以肯定的是,我查了一下。上述示例代码也适用于“Ctrl+Shift+C”。
| 归档时间: |
|
| 查看次数: |
1110 次 |
| 最近记录: |