QFontComboBox Class▲
-
Header: QFontComboBox
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
-
qmake: QT += widgets
-
Inherits: QComboBox
-
Group: QFontComboBox is part of basicwidgets
Detailed Description▲
The combobox is populated with an alphabetized list of font family names, such as Arial, Helvetica, and Times New Roman. Family names are displayed using the actual font when possible. For fonts such as Symbol, where the name is not representable in the font itself, a sample of the font is displayed next to the family name.
QFontComboBox is often used in toolbars, in conjunction with a QComboBox for controlling the font size and two QToolButtons for bold and italic.
When the user selects a new font, the currentFontChanged() signal is emitted in addition to currentIndexChanged().
Call setWritingSystem() to tell QFontComboBox to show only fonts that support a given writing system, and setFontFilters() to filter out certain types of fonts as e.g. non scalable fonts or monospaced fonts.
See Also▲
See also QComboBox, QFont, QFontInfo, QFontMetrics, QFontDatabase, Character Map Example
Member Type Documentation▲
enum QFontComboBox::FontFilter▲
flags QFontComboBox::FontFilters
This enum can be used to only show certain types of fonts in the font combo box.
Constant |
Value |
Description |
---|---|---|
QFontComboBox::AllFonts |
0 |
Show all fonts |
QFontComboBox::ScalableFonts |
0x1 |
Show scalable fonts |
QFontComboBox::NonScalableFonts |
0x2 |
Show non scalable fonts |
QFontComboBox::MonospacedFonts |
0x4 |
Show monospaced fonts |
QFontComboBox::ProportionalFonts |
0x8 |
Show proportional fonts |
The FontFilters type is a typedef for QFlags<FontFilter>. It stores an OR combination of FontFilter values.
Property Documentation▲
currentFont : QFont▲
This property holds the currently selected font
Access functions:
-
currentFont() const
-
void setCurrentFont(const &f)
Notifier signal:
-
void currentFontChanged(const &font)
See Also▲
See also currentIndex, currentText
fontFilters : FontFilters▲
This property holds the filter for the combobox
By default, all fonts are listed.
Access functions:
-
fontFilters() const
-
void setFontFilters( filters)
See Also▲
See also writingSystem
writingSystem : QFontDatabase::WritingSystem▲
This property holds the writing system that serves as a filter for the combobox
If script is QFontDatabase::Any (the default), all fonts are listed.
Access functions:
-
writingSystem() const
-
void setWritingSystem(QFontDatabase::WritingSystem)
See Also▲
See also fontFilters
Member Function Documentation▲
[explicit] QFontComboBox::QFontComboBox(QWidget *parent = nullptr)▲
Constructs a font combobox with the given parent.
[virtual] QFontComboBox::~QFontComboBox()▲
Destroys the combobox.
void QFontComboBox::currentFontChanged(const QFont &font)▲
This signal is emitted whenever the current font changes, with the new font.
Notifier signal for property currentFont.
See Also▲
See also currentFont
[since 6.3] std::optional<QFont> QFontComboBox::displayFont(const QString &fontFamily) const▲
Returns the font (if set) to be used to display a given fontFamily (when the combo is open).
This function was introduced in Qt 6.3.
See Also▲
See also setDisplayFont()
[override virtual protected] bool QFontComboBox::event(QEvent *e)▲
Reimplements: QComboBox::event(QEvent *event).
[since 6.3] QString QFontComboBox::sampleTextForFont(const QString &fontFamily) const▲
Returns the sample text to show after the font name (when the combo is open) for a given fontFamily.
This function was introduced in Qt 6.3.
See Also▲
See also setSampleTextForFont()
[since 6.3] QString QFontComboBox::sampleTextForSystem(QFontDatabase::WritingSystem writingSystem) const▲
Returns the sample text to show after the font name (when the combo is open) for a given writingSystem.
This function was introduced in Qt 6.3.
See Also▲
See also setSampleTextForSystem()
[since 6.3] void QFontComboBox::setDisplayFont(const QString &fontFamily, const QFont &font)▲
Sets the font to be used to display a given fontFamily (when the combo is open).
This function was introduced in Qt 6.3.
See Also▲
See also displayFont()
[since 6.3] void QFontComboBox::setSampleTextForFont(const QString &fontFamily, const QString &sampleText)▲
Sets the sampleText to show after the font name (when the combo is open) for a given fontFamily.
The sample text given with this function has priority over the one set with setSampleTextForSystem().
This function was introduced in Qt 6.3.
See Also▲
See also sampleTextForFont()
[since 6.3] void QFontComboBox::setSampleTextForSystem(QFontDatabase::WritingSystem writingSystem, const QString &sampleText)▲
Sets the sampleText to show after the font name (when the combo is open) for a given writingSystem.
The sample text given with setSampleTextForFont() has priority.
This function was introduced in Qt 6.3.
See Also▲
See also sampleTextForSystem()
[override virtual] QSize QFontComboBox::sizeHint() const▲
Reimplements: QComboBox::sizeHint() const.