QFontDialog Class
The QFontDialog class provides a dialog widget for selecting a font. More...
| Header: | #include <QFontDialog> |
| qmake: | QT += widgets |
| Inherits: | QDialog |
Public Types
| enum | FontDialogOption { NoButtons, DontUseNativeDialog, ScalableFonts, NonScalableFonts, MonospacedFonts, ProportionalFonts } |
Properties
- currentFont : QFont
- options : FontDialogOptions
Public Functions
| QFont | currentFont() const |
| QFontDialog::FontDialogOptions | options() const |
| void | setCurrentFont(const QFont &font) |
| void | setOptions(QFontDialog::FontDialogOptions options) |
Signals
| void | currentFontChanged(const QFont &font) |
Detailed Description
A font dialog is created through one of the static getFont() functions.
Examples:
bool ok; QFont font = QFontDialog::getFont( &ok, QFont("Helvetica [Cronyx]", 10), this); if (ok) { // the user clicked OK and font is set to the font the user selected } else { // the user canceled the dialog; font is set to the initial // value, in this case Helvetica [Cronyx], 10 }
The dialog can also be used to set a widget's font directly:
myWidget.setFont(QFontDialog::getFont(0, myWidget.font()));
If the user clicks OK the font they chose will be used for myWidget, and if they click Cancel the original font is used.

See also QFont, QFontInfo, QFontMetrics, QColorDialog, QFileDialog, and Standard Dialogs Example.
Member Type Documentation
enum QFontDialog::FontDialogOption
This enum specifies various options that affect the look and feel of a font dialog.
For instance, it allows to specify which type of font should be displayed. If none are specified all fonts available will be listed.
Note that the font filtering options might not be supported on some platforms (e.g. Mac). They are always supported by the non native dialog (used on Windows or Linux).
| Constant | Value | Description |
|---|---|---|
QFontDialog::NoButtons | 0x00000001 | Don't display OK and Cancel buttons. (Useful for "live dialogs".) |
QFontDialog::DontUseNativeDialog | 0x00000002 | Use Qt's standard font dialog on the Mac instead of Apple's native font panel. |
QFontDialog::ScalableFonts | 0x00000004 | Show scalable fonts |
QFontDialog::NonScalableFonts | 0x00000008 | Show non scalable fonts |
QFontDialog::MonospacedFonts | 0x00000010 | Show monospaced fonts |
QFontDialog::ProportionalFonts | 0x00000020 | Show proportional fonts |
This enum was introduced or modified in Qt 4.5.
See also options, setOption(), and testOption().
Property Documentation
currentFont : QFont
This property holds the current font of the dialog.
This property was introduced in Qt 4.5.
Access functions:
| QFont | currentFont() const |
| void | setCurrentFont(const QFont &font) |
Notifier signal:
| void | currentFontChanged(const QFont &font) |
options : FontDialogOptions
This property holds the various options that affect the look and feel of the dialog
By default, all options are disabled.
Options should be set before showing the dialog. Setting them while the dialog is visible is not guaranteed to have an immediate effect on the dialog (depending on the option and on the platform).
This property was introduced in Qt 4.5.
Access functions:
| QFontDialog::FontDialogOptions | options() const |
| void | setOptions(QFontDialog::FontDialogOptions options) |
See also setOption() and testOption().