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:
How do I do that? I don't seem to find a way to do that in Qt Creator.
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, eg in the menu entry (only visible in the application, not in QtDesigner).
In the 'Property Editor' are more options for the 'shortcuts' (eg make them translatable).
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.