6.0.0-rc4Source

QFontDialog Class

The QFontDialog class lets the user choose a font. More…

Header#include <QFontDialog>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQDialog

List of all members, including inherited members

Public Types

Public Functions

QFontDialog(QWidget *parent = nullptr)
QFontDialog(const QFont &initial, QWidget *parent = nullptr)
~QFontDialog()
voidsetCurrentFont(const QFont &font)
QFontcurrentFont() const
QFontselectedFont() const
voidsetOption(FontDialogOption option, bool on = true)
booltestOption(FontDialogOption option) const
voidsetOptions(FontDialogOptions options)
FontDialogOptionsoptions() const

Signals

voidcurrentFontChanged(const QFont &font)
voidfontSelected(const QFont &font)

Static Public Members

QFontgetFont(bool *ok, const QFont &initial, QWidget *parent = nullptr, const QString &title = QString(), FontDialogOptions options = FontDialogOptions())
QFontgetFont(bool *ok, QWidget *parent = nullptr)

Reimplemented Protected Functions

voiddone(int result)

Detailed Description

The dialog has a list of font families, of styles and of sizes, and a sample text in the current font. getFont() shows it and waits:

bool ok = false;
const QFont font = QFontDialog::getFont(&ok, editor->font(), window);
if (ok)
    editor->setFont(font);

The families are the generic Sans Serif, Serif and Monospace, then the families that fontconfig finds.

See also QFont.

Differences from Qt

The dialog is always drawn by Nt. The styles are Regular, Italic, Bold and Bold Italic whatever the family has, and there are no effects (underline, strike out) and no writing systems. The options that filter the families (ScalableFonts, MonospacedFonts and the others) are recorded but do not filter. There is no open() with a receiver. The texts are not translated.

Member Type Documentation

enum QFontDialog::FontDialogOption

Options for the dialog. FontDialogOptions is a typedef for QFlags<FontDialogOption>.

ConstantDescription
QFontDialog::NoButtonsNo OK and Cancel buttons, for a dialog that is used for its currentFontChanged() signal.
QFontDialog::DontUseNativeDialogAccepted for compatibility; the dialog is never native.
QFontDialog::ScalableFontsShow scalable fonts; recorded only.
QFontDialog::NonScalableFontsShow bitmap fonts; recorded only.
QFontDialog::MonospacedFontsShow monospaced fonts; recorded only.
QFontDialog::ProportionalFontsShow proportional fonts; recorded only.

typedef QFontDialog::FontDialogOptions

The FontDialogOptions type is a typedef for QFlags<FontDialogOption>. It stores an OR combination of FontDialogOption values.

Member Function Documentation

[explicit] QFontDialog::QFontDialog(QWidget *parent = nullptr)

Constructs a font dialog with the given parent. The current font is the default font of the application.

[explicit] QFontDialog::QFontDialog(const QFont &initial, QWidget *parent = nullptr)

Constructs a font dialog with the given parent and the initial current font.

[override] QFontDialog::~QFontDialog()

Destroys the font dialog.

QFont QFontDialog::currentFont() const

Returns the font that the user is picking.

See also setCurrentFont() and selectedFont().

[signal] void QFontDialog::currentFontChanged(const QFont &font)

This signal is emitted when the current font changes to font, as the user picks it.

[override, protected] void QFontDialog::done(int result)

Reimplements QDialog::done().

An accepted dialog records the selected font and emits fontSelected().

[signal] void QFontDialog::fontSelected(const QFont &font)

This signal is emitted when the dialog is accepted, with the chosen font.

[static] QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget *parent = nullptr, const QString &title = QString(), FontDialogOptions options = FontDialogOptions())

Shows a font dialog with the given parent, window title and options, starting at the initial font, and waits for the user. Returns the chosen font, or initial if the user canceled; ok, if given, is set to whether the user accepted.

[static] QFont QFontDialog::getFont(bool *ok, QWidget *parent = nullptr)

This is an overloaded function.

Shows a font dialog with the given parent, starting at the default font. ok, if given, is set to whether the user accepted.

FontDialogOptions QFontDialog::options() const

Returns the options of the dialog.

QFont QFontDialog::selectedFont() const

Returns the font that was chosen when the dialog was accepted.

See also currentFont().

void QFontDialog::setCurrentFont(const QFont &font)

Sets the current font to font, and selects its family, style and size in the lists.

See also currentFont().

void QFontDialog::setOption(FontDialogOption option, bool on = true)

Sets option if on is true, and clears it otherwise.

See also testOption().

void QFontDialog::setOptions(FontDialogOptions options)

Sets the options of the dialog to options.

See also options().

bool QFontDialog::testOption(FontDialogOption option) const

Returns whether option is set.