PyQt5 QSpinBox – 设置提示首选项
在本文中,我们将了解如何为旋转框设置提示首选项,可以将不同级别的提示应用于字形,以提高可能由像素密度保证的显示器的易读性。
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
下面是实现
# 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())
输出 :