Using the font dialog
In this recipe, we will learn to use a font dialog to apply different fonts and styles to the selected text.
We will make use of a Text Edit
widget and a Push Button
widget in this application. The push button, when clicked, will open the font dialog. The font and style selected from the font dialog will be applied to the text written in the Text Edit
widget.
In this recipe, we will be making use of the QFontDialog
class, which displays a Dialog
widget meant for selecting a font.
How to do it...
Let's create a new application based on the Dialog without Buttons
template by performing the following steps:
- Drag and drop a
Push Button
and aText Edit
widget onto the form. - Set the text property of the
Push Button
widget toChoose Font
. - Set the
objectName
property of thePush Button
widget topushButtonFont
. - Save the application with the name
demoFontDialog.ui
. - After performing the preceding steps, the application will appear as shown in the following screenshot:

The user interface...