0

What is the purpose of the '&' in the string in this line?

exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)

Likewise here:

fileMenu = menubar.addMenu('&File')
1
  • 4
    That's how you signal which character should be the keyboard shortcut for the action. e.g. alt-F S in most apps triggers the filemenu, and goes to the "S" option, which is generally "save", so you'd have .addMenu('&File') &F -> "alt-F" Commented Aug 29, 2016 at 15:14

1 Answer 1

2

The & character has a special purpose if you use it in the text of a QAction object: If the QAction object is used in a tool button, the character directly after the & symbol can be used as a keyboard shortcut for that button (in combination with the alt-key).

See http://doc.qt.io/qt-5/qaction.html (resp. http://doc.qt.io/qt-5/qaction.html#QAction-2).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.