0

How can I include the & character in a label. I've tried it, but it's not visible!

The first screenshot shows that I write the & character in the text field of a button. After confirming you can see screenshot 2. (I tried it in QT Designer)

Screenshot 1 Screenshot 2

This code example shows the problem:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot


class App(QWidget):

    def __init__(self):
        super().__init__()
        self.title = 'Keyboard'
        self.setGeometry(10,10,320,320)
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        button = QPushButton('&', self)
        button.move(100, 70)
        button.released.connect(self.on_released)
        self.show()

    @pyqtSlot()
    def on_released(self):
        print('PyQt5 button click')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())
Robin Fauser
  • 111
  • 1
  • 13
  • Of course not. Screenshot 2 is the final result without the & character. Even though I used an & character! I added an example! – Robin Fauser Mar 17 '22 at 16:21
  • 1
    For what it's worth, the answer in the question I linked does indeed solve your problem. tl;dr: `button = QPushButton('&&', self)`. – jfaccioni Mar 17 '22 at 16:32

0 Answers0