Why use the ampersand (&) character in PyQt Strings for GUI elements?

I've read several tutorials for PyQt and they use the ampersand (&) character in strings that are used to denote buttons. For example:

self.submitButton = QPushButton("&Submit")

      

I've searched for some explanation, but one problem is that conventional search engines think they are so smart and ignore character and temperament that it is annoying. When I add quotation marks around it, it only makes me find fewer results and nothing that explains anything about the weird "&". symbols.

  • This is something very basic and why doesn't anyone explain it?
  • Or is it PyQt specific?
  • And why should I add an unnecessary symbol?
  • Doesn't stubbing String unnecessarily?
  • What effect does it have on processing this string?

I also tried in python console:

a = "&abc"
b = "abc"
a == b

      

which returns false. Then I tried to give it a print function argument:

print(a)
print(b)

      

which just prints:

&abc
abc

      

So I still don't know what to do about it.

+3


source to share


1 answer


From msdn.microsoft.com : (not relevant to python itself, but the concept is the same)

Gets or sets a value that indicates whether the control interprets the ampersand (&) character in the control's Text property is an access key prefix.

If the UseMnemonic property is set to true and a mnemonic character (a character preceded by an ampersand) is specified in the label's Text property by pressing ALT +, the mnemonic character sets focus to the control that follows the label in tab order. You can use this to ensure correct keyboard navigation on controls on your form.

And from pyqt.sourceforge.net :



QLabel is often used as a label for an interactive widget. For this, the use of QLabel is a useful mechanism for adding mnemonics (see QKeySequence) that will set the keyboard focus to another widget.

eg:.

QLineEdit* phoneEdit = new QLineEdit(this);
QLabel* phoneLabel = new QLabel("&Phone:", this);
phoneLabel->setBuddy(phoneEdit);

      

+5


source







All Articles