English 中文(简体)
向纽特州转让短击钥匙——Qt C++
原标题:Assign shortcut keys to buttons - Qt C++
  • 时间:2011-01-07 19:50:18
  •  标签:
  • c++
  • qt

我已经利用Qt造物公司创建了一个GUI。 这是一种拖累和 drop。 现在,我要为所有县分配简短的关键。 在这里请让我知道如何这样做? 事先感谢你。

最佳回答

Your buttons probably have a slot connected to their clicked() signal.

为增加短击钥匙,你只是将短击钥匙<代码>(<>>>d()信号与同一位置连接起来。

在您的法典中,#include <QShortcut>,然后,你将能够添加一个捷径钥匙,用于诸如:

QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+O"), parent);
QObject::connect(shortcut, SIGNAL(activated()), receiver, SLOT(yourSlotHere()));

Where parent is the parent of your shortcut (for example the main window), yourSlotHere() is the name of the slot you want the shortcut to call, and receiver the object where yourSlotHere() is.

将“Ctrl+O”栏改为“你想要指派的任何短.”。

也可在

问题回答

或者,如果 short的关键与 but文的某些特性相对应,则你可以预先保留<代码>和p;。 如果您希望打字面&,则使用&&

从“国际不动产/未爆炸”的角度来看,你实际上想要的是,不仅触发了与纽特触发器相同的位置(这是公认的答案所建议的解决办法),而且你也想直观地将压力的纽特区联系起来,以确保用户能够清楚地看到正在启动的行动。 下面是我对我确认的<代码>QPushButtons的用法。

// I have this function in my  utils  module.
void bindShortcut(QAbstractButton *button, const QKeySequence &shortcut)  
{
    QObject::connect(new QShortcut(shortcut, button), &QShortcut::activated, [button](){ button->animateClick(); });
}

// and then I use it like this
auto *confirmButton = new QPushButton(tr("Confirm"));
connect(confirmButton, &QPushButton::clicked, ... some slot of yours to do the actual work);
bindShortcut(confirmButton, Qt::Key_Enter);
bindShortcut(confirmButton, Qt::Key_Return);

如果你不使用QtDesigner,我想这是最好的答案。 否则,你就能够像另一个答案所显示的那样,在设计人中很容易设定捷径。

btnOpen = new QPushButton(tr("Open"));
btnOpen->setStatusTip(tr("Open file"));
btnOpen->setShortcut(QKeySequence("Ctrl+O"));




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签