FontDialog QML Type

A native font dialog. 更多...

import 语句: import Qt.labs.platform 1.1
Since: Qt 5.8
继承:

Dialog

特性

详细描述

The FontDialog type provides a QML API for native platform font dialogs.

To show a font dialog, construct an instance of FontDialog, set the desired properties, and call open() currentFont property can be used to determine the currently selected font in the dialog. The font property is updated only after the final selection has been made by accepting the dialog.

MenuItem {
    text: "Font"
    onTriggered: fontDialog.open()
}
FontDialog {
    id: fontDialog
    currentFont.family: document.font
}
MyDocument {
    id: document
    font: fontDialog.font
}
					
					

可用性

A native platform font dialog is currently available on the following platforms:

  • macOS
  • Linux (when running with the GTK+ platform theme)

The Qt Labs Platform module uses Qt Widgets as a fallback on platforms that do not have a native implementation available. Therefore, applications that use types from the Qt Labs Platform module should link to QtWidgets and use QApplication 而不是 QGuiApplication .

要链接到 QtWidgets library, add the following to your qmake project file:

QT += widgets
					

Create an instance of QApplication in main() :

#include <QApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}
					

注意: Types in Qt.labs modules are not guaranteed to remain compatible in future versions.

特性文档编制

currentFont : font

This property holds the currently selected font in the dialog.

不像 font 特性, currentFont property is updated while the user is selecting fonts in the dialog, even before the final selection has been made.

另请参阅 font .

font : font

This property holds the final accepted font.

不像 currentFont 特性, font property is not updated while the user is selecting fonts in the dialog, but only after the final selection has been made. That is, when the user has clicked OK to accept a font. Alternatively, the accepted() signal can be handled to get the final selection.

另请参阅 currentFont and accepted() .

options : flags

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

Available options:

常量 描述
FontDialog.ScalableFonts Show scalable fonts.
FontDialog.NonScalableFonts Show non-scalable fonts.
FontDialog.MonospacedFonts Show monospaced fonts.
FontDialog.ProportionalFonts Show proportional fonts.
FontDialog.NoButtons 不显示 OK and Cancel buttons (useful for "live dialogs").