Home » PyQt5 QFontDialog widget

PyQt5 QFontDialog widget

by maxguy71

In this article we look at the QFontDialog

It provides a dialog widget for selecting a font and they are used to select different fonts and various properties such as size and style

It is popup type widget in PyQt5

The class contains a static method called getFont(). It displays the font selector dialog.

The setCurrentFont() method sets the default Font of the dialog.


This is a basic example

The following example has a button and a label. When the button is clicked, a font dialog pops up. The font chosen by the user along with any other settings is applied to the text on the label.

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, \
    QPushButton, QSizePolicy, QLabel, QFontDialog

class MyApp(QWidget):

    def __init__(self):

    def initUI(self):

        btn = QPushButton('Change font properties', self)
        btn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        btn.move(20, 20)

        vbox = QVBoxLayout()

        self.lbl = QLabel('This is some test text for the font', self)
        self.lbl.move(130, 20)


        self.setWindowTitle('Font Dialog')
        self.setGeometry(300, 300, 250, 200)

    def showDialog(self):
        font, ok = QFontDialog.getFont()
        if ok:

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyApp()

When you run this you will see the following

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More