PyQt5 QSpinBox – Setting Hinting Preference
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
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__()
self .setWindowTitle( "Python " )
self .setGeometry( 100 , 100 , 600 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
self .spin = QSpinBox( self )
self .spin.setGeometry( 100 , 100 , 250 , 40 )
self .spin.setRange( 0 , 999999 )
self .spin.setPrefix( "PREFIX " )
self .spin.setSuffix( " SUFFIX" )
font = QFont( 'Arial' )
font.setHintingPreference(QFont.PreferFullHinting)
self .spin.setFont(font)
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...