Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

PyQt QFont class:

QFont is a PyQt5 class for handling fonts. We can modify the Font properties with this class. We can also create a Dialog to select the font by QFontDialog widget.

syntax of PyQt QFont class:

font = QFont()

Example:

Following are the properties of font and we can modify all these.

from PyQt5.QtGui import QFont

# Create a QFont object
font = QFont()

# Set the font family
font.setFamily('Arial')

# Set the font size
font.setPointSize(14)

# Set the font weight to bold
font.setBold(True)

# Set the font italic
font.setItalic(True)

# Set the font underline
font.setUnderline(True)

# Set the font strikeout
font.setStrikeOut(True)

# Create a QLabel widget and set the font
label = QLabel('Hello World')
label.setFont(font)

# Show the label
label.show()

The above example is a dummy example, you can use this code in your real code.

You can also use the setPixelSize() method to set the font size in pixels, and the setWeight() method to set the font weight to a value between 0 and 99, with 0 being the thinnest and 99 the thickest.

The post PyQt QFont class: appeared first on Artificial Intelligence.



This post first appeared on Learn Python, please read the originial post: here

Share the post

PyQt QFont class:

×

Subscribe to Learn Python

Get updates delivered right to your inbox!

Thank you for your subscription

×