문제

I created the shortcut events, such as:

new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));

But now I would like to show "Ctrl+Q" in the menu entry here:

Exit

How do I do that? I don't seem to find a way to do that in Qt Creator.

도움이 되었습니까?

해결책 2

Generally you would use QAction class for this, so you would have a QMenu to which you will add actions, in your case CLOSE. Then you can use SetShortcut to add "CTRL + Q" in menu.

pNewAction->setShortcut(QString(strAccel.c_str()));

where pNewAction is of type QAction.

다른 팁

You can set the shortcut keys in the QtDesigner in the 'Action Editor' (Tab at the bottom, the 'Signal/Slot Editor' tab is selected by default).

Here all defined QActions are listed. A double click on a field in the 'shortcut' column will open the wanted dialog.

This will add the shortcut to the QAction (create triggered events) and set it as visibile text, e.g. in the menu entry (only visible in the application, not in QtDesigner).

In the 'Property Editor' are more options for the 'shortcuts' (e.g. make them translatable).

Add shortcuts to QActions in the Action Editor

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top