from PyQt5.QtGui import QFontDatabase font_db = QFontDatabase() font_families = font_db.families() print(font_families)
from PyQt5.QtGui import QFontDatabase, QFont font_db = QFontDatabase() # Load custom font file font_id = font_db.addApplicationFont("my_custom_font.ttf") # Get the family name of the custom font font_families = font_db.applicationFontFamilies(font_id) custom_font_family = font_families[0] # Set a label to use the custom font label = QLabel("Custom font example") label.setFont(QFont(custom_font_family, 24))This example shows how to load a custom font file (in this case, "my_custom_font.ttf") and register it with the database using the `addApplicationFont()` method. Once registered, the font can be accessed by its family name using `applicationFontFamilies()`. Finally, a QLabel widget is created and set to use the custom font. The PyQt5.QtGui package contains the QFontDatabase class and other classes for working with fonts, including QFont, QFontInfo, and QFontMetrics.