Skip to content
Related Articles

Related Articles

PyQt5 QSpinBox – Setting Hinting Preference

Improve Article
Save Article
Like Article
  • Last Updated : 22 May, 2020

In this article we will see how we can set hinting preference to the spin box, there are different levels of hinting that can be applied to glyphs to improve legibility on displays where it might be warranted by the density of pixels.

Below is the types of preference are available for spin box

PreferDefaultHinting : Use the default hinting level for the spin box

PreferNoHinting : It render text without hinting the outlines of the glyphs. The text layout will be typographically accurate and scalable, using the same metrics as are used e.g. when printing.

PreferVerticalHinting : It render text with no horizontal hinting, but align glyphs to the pixel grid in the vertical direction. The text will appear crisper on displays where the density is too low to give an accurate rendering of the glyphs.

PreferFullHinting : It render text with hinting in both horizontal and vertical directions. The text will be altered to optimize legibility on the spin box

In order to do this we usesetHintingPreference method with the QFont object of the spin box

Syntax : font.setHintingPreference(QFont.PreferFullHinting)

Argument : It takes QFont object or we can pass preference value as argument

Return : It returns None

Below is the implementation




# 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(0, 999999)
  
        # setting prefix to spin
        self.spin.setPrefix("PREFIX ")
  
        # setting suffix to spin
        self.spin.setSuffix(" SUFFIX")
  
        # getting font of the spin box
        font = QFont('Arial')
  
        # setting hinting preference
        font.setHintingPreference(QFont.PreferFullHinting)
  
        # setting back this font to the spin box
        self.spin.setFont(font)
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

Output :


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!