from qtpy.QtGui import QFont # Creating a font object with specific properties font = QFont("Arial", 14)
from qtpy.QtGui import QFont from qtpy.QtWidgets import QLabel # Creating a font object font = QFont("Arial", 14) # Creating a label and setting the font label = QLabel("Hello, world!") label.setFont(font)
from qtpy.QtGui import QFont from qtpy.QtWidgets import QLabel # Creating a label with default font label = QLabel("Hello, world!") # Changing the font properties label.setFont(QFont("Times New Roman", 20, QFont.Bold)) # Displaying the label label.show()This code creates a QLabel object with the text "Hello, world!", and then changes its font to Times New Roman, font size 20 and bold style using the setFont() method. Finally, the label is displayed on the screen with the show() method. Overall, these examples demonstrate how to use the QFont class from the QtGui module of qtpy package to create and apply fonts for text in a GUI application.