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

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.

A font dialog in the Fusion widget style.

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).

ConstantValueDescription
QFontDialog::NoButtons0x00000001Don't display OK and Cancel buttons. (Useful for "live dialogs".)
QFontDialog::DontUseNativeDialog0x00000002Use Qt's standard font dialog on the Mac instead of Apple's native font panel.
QFontDialog::ScalableFonts0x00000004Show scalable fonts
QFontDialog::NonScalableFonts0x00000008Show non scalable fonts
QFontDialog::MonospacedFonts0x00000010Show monospaced fonts
QFontDialog::ProportionalFonts0x00000020Show 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().