QFontComboBox 类

QFontComboBox 小部件是让用户选择字体系列的组合框。 更多...

头: #include <QFontComboBox>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: QComboBox

公共类型

enum FontFilter { AllFonts, ScalableFonts, NonScalableFonts, MonospacedFonts, ProportionalFonts }
flags FontFilters

特性

公共函数

QFontComboBox (QWidget * parent = nullptr)
virtual ~QFontComboBox ()
QFont currentFont () const
std::optional<QFont> displayFont (const QString & fontFamily ) const
QFontComboBox::FontFilters fontFilters () const
QString sampleTextForFont (const QString & fontFamily ) const
QString sampleTextForSystem (QFontDatabase::WritingSystem writingSystem ) const
void setDisplayFont (const QString & fontFamily , const QFont & font )
void setFontFilters (QFontComboBox::FontFilters filters )
void setSampleTextForFont (const QString & fontFamily , const QString & sampleText )
void setSampleTextForSystem (QFontDatabase::WritingSystem writingSystem , const QString & sampleText )
void setWritingSystem (QFontDatabase::WritingSystem)
QFontDatabase::WritingSystem writingSystem () const

重实现公共函数

virtual QSize sizeHint () const override

公共槽

void setCurrentFont (const QFont & f )

信号

void currentFontChanged (const QFont & font )

重实现保护函数

virtual bool event (QEvent * e ) override

详细描述

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 QToolButton s for bold and italic.

When the user selects a new font, the currentFontChanged () signal is emitted in addition to currentIndexChanged ().

调用 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.

Screenshot of QFontComboBox on Windows Vista

另请参阅 QComboBox , QFont , QFontInfo , QFontMetrics , QFontDatabase ,和 字符映射范例 .

成员类型文档编制

enum QFontComboBox:: FontFilter
flags QFontComboBox:: FontFilters

This enum can be used to only show certain types of fonts in the font combo box.

常量 描述
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.

特性文档编制

currentFont : QFont

This property holds the currently selected font

访问函数:

QFont currentFont () const
void setCurrentFont (const QFont & f )

通知程序信号:

void currentFontChanged (const QFont & font )

另请参阅 currentIndex and currentText .

fontFilters : FontFilters

This property holds the filter for the combobox

By default, all fonts are listed.

访问函数:

QFontComboBox::FontFilters fontFilters () const
void setFontFilters (QFontComboBox::FontFilters filters )

另请参阅 writingSystem .

writingSystem : QFontDatabase::WritingSystem

This property holds the writing system that serves as a filter for the combobox

script is QFontDatabase::Any (the default), all fonts are listed.

访问函数:

QFontDatabase::WritingSystem writingSystem () const
void setWritingSystem (QFontDatabase::WritingSystem)

另请参阅 fontFilters .

成员函数文档编制

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

构造字体组合框采用给定 parent .

[虚拟] QFontComboBox:: ~QFontComboBox ()

销毁组合框。

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

This signal is emitted whenever the current font changes, with the new font .

注意: 通知程序信号对于特性 currentFont .

另请参阅 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).

该函数在 Qt 6.3 引入。

另请参阅 setDisplayFont ().

[override virtual protected] bool QFontComboBox:: event ( QEvent * e )

重实现: 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 .

该函数在 Qt 6.3 引入。

另请参阅 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 .

该函数在 Qt 6.3 引入。

另请参阅 setSampleTextForSystem ().

[since 6.3] void QFontComboBox:: setDisplayFont (const QString & fontFamily , const QFont & font )

设置 font to be used to display a given fontFamily (when the combo is open).

该函数在 Qt 6.3 引入。

另请参阅 displayFont ().

[since 6.3] void QFontComboBox:: setSampleTextForFont (const QString & fontFamily , const QString & sampleText )

设置 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 ().

该函数在 Qt 6.3 引入。

另请参阅 sampleTextForFont ().

[since 6.3] void QFontComboBox:: setSampleTextForSystem ( QFontDatabase::WritingSystem writingSystem , const QString & sampleText )

设置 sampleText to show after the font name (when the combo is open) for a given writingSystem .

The sample text given with setSampleTextForFont () has priority.

该函数在 Qt 6.3 引入。

另请参阅 sampleTextForSystem ().

[override virtual] QSize QFontComboBox:: sizeHint () const

重实现: QComboBox::sizeHint() const .