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 Buttonand aText Editwidget onto the form. - Set the text property of the
Push Buttonwidget toChoose Font. - Set the
objectNameproperty of thePush Buttonwidget 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...