QFontDialog 类

QFontDialog 类提供用于选择字体的对话框 Widget。 更多...

头: #include <QFontDialog>
qmake: QT += widgets
继承: QDialog

公共类型

enum FontDialogOption { NoButtons, DontUseNativeDialog, ScalableFonts, NonScalableFonts, MonospacedFonts, ProportionalFonts }
flags FontDialogOptions

特性

公共函数

QFontDialog (const QFont & initial , QWidget * parent = nullptr)
QFontDialog (QWidget * parent = nullptr)
QFont currentFont () const
void open (QObject * receiver , const char * member )
QFontDialog::FontDialogOptions options () const
QFont selectedFont () const
void setCurrentFont (const QFont & font )
void setOption (QFontDialog::FontDialogOption option , bool on = true)
void setOptions (QFontDialog::FontDialogOptions options )
bool testOption (QFontDialog::FontDialogOption option ) const

重实现公共函数

virtual void setVisible (bool visible ) override

信号

void currentFontChanged (const QFont & font )
void fontSelected (const QFont & font )

静态公共成员

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

重实现保护函数

virtual void changeEvent (QEvent * e ) override
virtual void done (int result ) override

详细描述

字体对话框的创建是透过某一静态 getFont () 函数。

范例:

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.

另请参阅 QFont , QFontInfo , QFontMetrics , QColorDialog , QFileDialog ,和 标准对话框范例 .

成员类型文档编制

enum QFontDialog:: FontDialogOption
flags QFontDialog:: FontDialogOptions

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

常量 描述
QFontDialog::NoButtons 0x00000001 不显示 OK and Cancel buttons. (Useful for "live dialogs".)
QFontDialog::DontUseNativeDialog 0x00000002 Use Qt's standard font dialog on the Mac instead of Apple's native font panel.
QFontDialog::ScalableFonts 0x00000004 Show scalable fonts
QFontDialog::NonScalableFonts 0x00000008 Show non scalable fonts
QFontDialog::MonospacedFonts 0x00000010 Show monospaced fonts
QFontDialog::ProportionalFonts 0x00000020 Show proportional fonts

该枚举在 Qt 4.5 引入或被修改。

FontDialogOptions 类型是 typedef 对于 QFlags <FontDialogOption>. It stores an OR combination of FontDialogOption values.

另请参阅 options , setOption (),和 testOption ().

特性文档编制

currentFont : QFont

此特性保持对话框的当前字体。

该特性在 Qt 4.5 引入。

访问函数:

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

通知程序信号:

void currentFontChanged (const QFont & font )

options : FontDialogOptions

This property holds the various options that affect the look and feel of the dialog

默认情况下,所有选项是被禁用的。

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

该特性在 Qt 4.5 引入。

访问函数:

QFontDialog::FontDialogOptions options () const
void setOptions (QFontDialog::FontDialogOptions options )

另请参阅 setOption () 和 testOption ().

成员函数文档编制

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

Constructs a standard font dialog with the given parent 和指定 initial font.

该函数在 Qt 4.5 引入。

QFontDialog:: QFontDialog ( QWidget * parent = nullptr)

Constructs a standard font dialog.

使用 setCurrentFont () to set the initial font attributes.

The parent parameter is passed to the QDialog 构造函数。

该函数在 Qt 4.5 引入。

另请参阅 getFont ().

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

This signal is emitted when the current font is changed. The new font is specified in font .

The signal is emitted while a user is selecting a font. Ultimately, the chosen font may differ from the font currently selected.

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

该函数在 Qt 4.5 引入。

另请参阅 currentFont , fontSelected (),和 selectedFont ().

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

This signal is emitted when a font has been selected. The selected font is specified in font .

The signal is only emitted when a user has chosen the final font to be used. It is not emitted while the user is changing the current font in the font dialog.

该函数在 Qt 4.5 引入。

另请参阅 selectedFont (), currentFontChanged (),和 currentFont .

[override virtual protected] void QFontDialog:: changeEvent ( QEvent * e )

重实现: QWidget::changeEvent (QEvent *event).

QFont QFontDialog:: currentFont () const

Returns the current font.

注意: Getter function for property currentFont.

该函数在 Qt 4.5 引入。

另请参阅 setCurrentFont () 和 selectedFont ().

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

重实现: QDialog::done (int r).

关闭对话框并将其结果代码设为 result 。若此对话框的展示是采用 exec (),done() 导致本地事件循环的完成,且 exec () 返回 result .

另请参阅 QDialog::done ().

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

执行模态字体对话框并返回字体。

If the user clicks OK , the selected font is returned. If the user clicks Cancel initial font is returned.

The dialog is constructed with the given parent and the options specified in options . title is shown as the window title of the dialog and initial is the initially selected font. If the ok parameter is not-null, the value it refers to is set to true if the user clicks OK , and set to false if the user clicks Cancel .

范例:

bool ok;
QFont font = QFontDialog::getFont(&ok, QFont("Times", 12), this);
if (ok) {
    // 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 Times, 12.
}
					

The dialog can also be used to set a widget's font directly:

myWidget.setFont(QFontDialog::getFont(0, myWidget.font()));
					

In this example, if the user clicks OK the font they chose will be used, and if they click Cancel the original font is used.

警告: 不要删除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFontDialog 构造函数。

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

这是重载函数。

执行模态字体对话框并返回字体。

If the user clicks OK , the selected font is returned. If the user clicks Cancel , the Qt default font is returned.

The dialog is constructed with the given parent 。若 ok parameter is not-null, the value it refers to is set to true if the user clicks OK , and false if the user clicks Cancel .

范例:

bool ok;
QFont font = QFontDialog::getFont(&ok, this);
if (ok) {
    // font is set to the font the user selected
} else {
    // the user canceled the dialog; font is set to the default
    // application font, QApplication::font()
}
					

警告: 不要删除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFontDialog 构造函数。

void QFontDialog:: open ( QObject * receiver , const char * member )

打开对话框并连接其 fontSelected () 信号到槽,指定通过 receiver and member .

将从槽断开信号连接,当关闭对话框时。

该函数在 Qt 4.5 引入。

QFont QFontDialog:: selectedFont () const

Returns the font that the user selected by clicking the OK or equivalent button.

注意: This font is not always the same as the font held by the currentFont property since the user can choose different fonts before finally selecting the one to use.

void QFontDialog:: setCurrentFont (const QFont & font )

Sets the font highlighted in the QFontDialog 到给定 font .

注意: setter 函数对于特性 currentFont .

该函数在 Qt 4.5 引入。

另请参阅 currentFont () 和 selectedFont ().

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

设置给定 option 为被启用若 on 为 true;否则,清零给定 option .

另请参阅 options and testOption ().

[override virtual] void QFontDialog:: setVisible ( bool visible )

重实现: QDialog::setVisible (bool visible).

bool QFontDialog:: testOption ( QFontDialog::FontDialogOption option ) const

返回 true 若给定 option 被启用;否则,返回 false。

另请参阅 options and setOption ().