QPushButton *quitButton = new QPushButton("&Quit");
Why add a &
to the Quit
? Removing &
and it seems the code behaves the same.
QPushButton *quitButton = new QPushButton("&Quit");
Why add a &
to the Quit
? Removing &
and it seems the code behaves the same.
The ampersand makes the button respond to a particular key-combination. In your case, if you press ALT + Q it will force the button to be pushed.
From Qt
The QPushButton widget provides a command button.
The push button, or command button, is perhaps the most commonly used widget in any graphical user interface. Push (click) a button to command the computer to perform some action, or to answer a question. Typical buttons are OK, Apply, Cancel, Close, Yes, No and Help.
A command button is rectangular and typically displays a text label describing its action. A shortcut key can be specified by preceding the preferred character with an ampersand in the text. For example:
QPushButton *button = new QPushButton("&Download", this);
In this example the shortcut is Alt+D. See the QShortcut documentation for details (to display an actual ampersand, use '&&').