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

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

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

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

可用选项

常量说明
FontDialog.ScalableFonts显示可缩放字体。
FontDialog.NonScalableFonts显示不可缩放字体。
FontDialog.MonospacedFonts显示单行字体。
FontDialog.ProportionalFonts显示比例字体。
FontDialog.NoButtons不显示OpenCancel 按钮(对 "实时对话框 "有用)。
FontDialog.DontUseNativeDialog强制对话框使用非本地快速实现。

selectedFont : font

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

用户在对话框中选择字体时,甚至在最终选择之前,selectedFont 属性都会更新。

可以处理accepted() 信号来获取最终选择。当用户点击Open 接受字体后,accepted() 信号的信号处理程序可查询 selectedFont 属性,以获取用户最终选择的字体。

另请参见 currentFontaccepted()。


© 2025 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.