In this article we will see how we can set the style name of the spin box’s text. Style name is used when developer created a custom style and wanted to name it for its own use, making style name easier to understand.
Note : Properties like style() and weight() will be ignored for font matching, though they may be simulated afterwards if supported by the platform’s font engine.
In order to do this we use setStyleName
method with the QFont object of the spin box.
Syntax : font.setStyleName(name)
Argument : It takes string 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 = self .spin.font()
font.setStyleName( "Geek" )
self .spin.setFont(font)
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
