PyQt5 QSpinBox - Getting the size of the font Last Updated : 28 May, 2020 Comments Improve Suggest changes Like Article Like Report In this article we will see how we can get size of the spin box's font i.e text. In order to get the size object we have to get the QFontMetrics object of the size box to get the size. The size will be in pixels. In order to do this we use size method with the spin box's QFontMetrics object. Syntax : font_metrics.size(0, text) Argument : It takes two argument one is the integer value which refer to the flags for example 0 represent single line text and second is the spin box text. Return : It returns QSize object. Below is the implementation Python3 1== # importing libraries from PyQt5.QtWidgets import * from PyQt5 import QtCore, QtGui from PyQt5.QtGui import * from PyQt5.QtCore import * import sys class Window(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 def UiComponents(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(1, 999999) # setting prefix to spin self.spin.setPrefix("PREFIX ") # setting suffix to spin self.spin.setSuffix(" SUFFIX") # setting over line to the font font = self.spin.font() font.setOverline(True) self.spin.setFont(font) # creating a label label = QLabel(self) # making label multi line label.setWordWrap(True) # setting geometry to the label label.setGeometry(100, 200, 300, 60) # getting font metrics f_metrics = self.spin.fontMetrics() # text text = self.spin.text() # getting the size object value = f_metrics.size(0, text) # setting text to the label label.setText("Size : " + str(value)) # create pyqt5 app App = QApplication(sys.argv) # create the instance of our Window window = Window() # start the app sys.exit(App.exec()) Output : Comment More infoAdvertise with us Next Article PyQt5 QSpinBox - Getting style of the text R rakshitarora Follow Improve Article Tags : Python Python-PyQt Python-gui Python PyQt-SpinBox Practice Tags : python Similar Reads PyQt5 QSpinBox - Getting the line width of the font In this article we will see how we can get the line width of the spin box font. Line width is the width of the underline and strikeout lines, adjusted for the point size of the font. In order to do this we use lineWidth method with the spin box's QFontMetrics object. Syntax : font_metrics.lineWidth( 2 min read PyQt5 QSpinBox - Getting style of the text In this article we will see how we can get the style of the spin box text, spin box has many styles available for its text for example StyleOblique, StyleNormal and StyleItalic by default it is style is set to the StyleNormal style. We can set style to it with the help of setStyle methodIn order to 2 min read PyQt5 QSpinBox - Getting the frame size In this article we will see how we can get the frame size of the spin box. Frame size is the spin box size relative to its parent including any window frame. By default, frame size of the spin box contains a value that depends on the user's platform and screen geometry. In order to do this we use fr 2 min read PyQt5 QSpinBox - Getting ascent of the font In this article we will see how we can get the ascent of the spin box's font i.e text. The ascent of a font is the distance from the baseline to the highest position characters extend to. In practice, some font designers break this rule, e.g. when they put more than one accent on top of a character, 2 min read PyQt5 QSpinBox - Getting the leading value of the font In this article we will see how we can get the leading value of the spin box's font. Leading value of the text means the distance between two baselines of lines of type. The word 'leading' originates from the strips of lead hand-typesetters used to use to space out lines of text evenly. The word lea 2 min read PyQt5 QSpinBox - Getting descent of the font In this article we will see how we can get the descent of the spin box's font i.e text. The descent is the distance from the base line to the lowest point characters extend to. In practice, some font designers break this rule, e.g. to accommodate an unusual character in an exotic language, so it is 2 min read Like