本页内容

FontDialog QML Type

字体对话框。更多...

Import Statement: import QtQuick.Dialogs
Since: Qt 6.2
Inherits:

Dialog

属性

详细说明

FontDialog 类型为字体对话框提供了一个 QML API。

用户可以通过字体对话框查看并选择不同的字体

要显示字体对话框,请创建一个 FontDialog 实例,设置所需属性,并调用 `open()`。可通过 `currentFont ` 属性确定对话框中当前选中的字体。`selectedFont ` 属性仅在通过接受对话框完成最终选择后才会更新。

MenuItem {
    text: "Font"
    onTriggered: fontDialog.open()
}

FontDialog {
    id: fontDialog
    currentFont.family: document.font
}

MyDocument {
    id: document
    font: fontDialog.selectedFont
}

可用性

目前,以下平台支持原生平台字体对话框:

  • iOS
  • Linux(在 GTK+ 平台主题下运行时)
  • macOS

Qt Quick Dialogs 在没有原生实现的平台上,会使用Qt Quick 实现作为备用方案。

属性文档

options : flags

该属性包含影响对话框外观和风格的各种选项。

默认情况下,未设置任何选项,这意味着将显示所有字体类型,且对话框会显示标准的“Select ”和“Cancel ”按钮。

应在显示对话框之前设置这些选项。在对话框可见时进行设置,不能保证会立即对对话框产生影响(具体取决于选项和平台)。

可用选项:

常量描述
FontDialog.ScalableFonts显示可缩放字体。
FontDialog.NonScalableFonts显示不可缩放字体。
FontDialog.MonospacedFonts显示等宽字体。
FontDialog.ProportionalFonts显示比例字体。
FontDialog.NoButtons不显示“Open ”和“Cancel ”按钮(适用于“实时对话框”)。
FontDialog.DontUseNativeDialog强制对话框使用非原生的快速实现。

selectedFont : font

该属性保存对话框中当前选中的字体。

当用户在对话框中选择字体时,selectedFont 属性会实时更新,即使最终选择尚未确定。

可以通过处理 `accepted()` 信号来获取最终的选择。当用户单击“Select ”(或“Open ”,具体取决于平台)以接受一种字体时,`accepted()` 信号的信号处理程序可以查询 `selectedFont` 属性,以获取用户最终选择的字体。

另请参阅 currentFont 和accepted()。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.