PyQt5 QSpinBox – Setting Hinting Preference

In this article we will see how we can check if the text of the spin box is fixed pitch or not, a mono-spaced font, also called a fixed-pitch, fixed-width, or non-proportional font, is a font whose letters and characters each occupy the same amount of horizontal space. This contrasts with variable-width fonts, where the letters and spacings have different widths. In order to get the information about the font we have to get the QFontInfo object of spin box which can be done using fontInfo method.
In order to do this we use fixedPitch method with the QFontInfo object of the spin box Syntax : font_info.fixedPitch() Argument : It takes no argument Return : It returns bool
Below is the implementation
Python3
| # importing librariesfromPyQt5.QtWidgets import*fromPyQt5 importQtCore, QtGuifromPyQt5.QtGui import*fromPyQt5.QtCore import*importsysclassWindow(QMainWindow):    def__init__(self):        super().__init__()        # setting title        self.setWindowTitle("Python ")        # setting geometry        self.setGeometry(100, 100, 600, 400)        # calling method        self.UiComponents()        # showing all the widgets        self.show()        # method for widgets    defUiComponents(self):        # creating spin box        self.spin =QSpinBox(self)        # setting geometry to spin box        self.spin.setGeometry(100, 100, 250, 40)        # setting range to the spin box        self.spin.setRange(0, 999999)        # setting prefix to spin        self.spin.setPrefix("PREFIX ")        # setting suffix to spin        self.spin.setSuffix(" SUFFIX")               # creating a label        label =QLabel(self)        # setting geometry to the label        label.setGeometry(100, 200, 300, 60)        # getting the font info        font_info =self.spin.fontInfo()        # getting fixed pitch status of text        check =font_info.fixedPitch()        # setting text to the label        label.setText("Fixed Pitch ? : " +str(check))# create pyqt5 appApp =QApplication(sys.argv)# create the instance of our Windowwindow =Window()# start the appsys.exit(App.exec()) | 
Output : 
 
				 
					


