QFontDialog Class
The QFontDialog class lets the user choose a font. More…
| Header | #include <QFontDialog> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QDialog |
List of all members, including inherited members
Public Types
| enum | FontDialogOption |
| typedef | FontDialogOptions |
Public Functions
| QFontDialog(QWidget *parent = nullptr) | |
| QFontDialog(const QFont &initial, QWidget *parent = nullptr) | |
| ~QFontDialog() | |
| void | setCurrentFont(const QFont &font) |
| QFont | currentFont() const |
| QFont | selectedFont() const |
| void | setOption(FontDialogOption option, bool on = true) |
| bool | testOption(FontDialogOption option) const |
| void | setOptions(FontDialogOptions options) |
| FontDialogOptions | options() const |
Signals
| void | currentFontChanged(const QFont &font) |
| void | fontSelected(const QFont &font) |
Static Public Members
| QFont | getFont(bool *ok, const QFont &initial, QWidget *parent = nullptr, const QString &title = QString(), FontDialogOptions options = FontDialogOptions()) |
| QFont | getFont(bool *ok, QWidget *parent = nullptr) |
Reimplemented Protected Functions
| void | done(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>.
| Constant | Description |
|---|---|
QFontDialog::NoButtons | No OK and Cancel buttons, for a dialog that is used for its currentFontChanged() signal. |
QFontDialog::DontUseNativeDialog | Accepted for compatibility; the dialog is never native. |
QFontDialog::ScalableFonts | Show scalable fonts; recorded only. |
QFontDialog::NonScalableFonts | Show bitmap fonts; recorded only. |
QFontDialog::MonospacedFonts | Show monospaced fonts; recorded only. |
QFontDialog::ProportionalFonts | Show 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
QFontDialog::QFontDialog(QWidget *parent = nullptr)
Constructs a font dialog with the given parent. The current font is the default font of the application.
QFontDialog::QFontDialog(const QFont &initial, QWidget *parent = nullptr)
Constructs a font dialog with the given parent and the initial current font.
QFontDialog::~QFontDialog()
Destroys the font dialog.
QFont QFontDialog::currentFont() const
Returns the font that the user is picking.
See also setCurrentFont() and selectedFont().
void QFontDialog::currentFontChanged(const QFont &font)
This signal is emitted when the current font changes to font, as the user picks it.
void QFontDialog::done(int result)
Reimplements QDialog::done().
An accepted dialog records the selected font and emits fontSelected().
void QFontDialog::fontSelected(const QFont &font)
This signal is emitted when the dialog is accepted, with the chosen font.
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.
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.