FontDialog QML Type

Dialog component for choosing a font. 更多...

import 语句: import QtQuick.Dialogs 1.3
Since: Qt 5.2

特性

方法

详细描述

FontDialog allows the user to select a font. The dialog is initially invisible. You need to set the properties as desired first, then set visible to true or call open() .

Here is a minimal example to open a font dialog and exit after the user chooses a font:

import QtQuick 2.2
import QtQuick.Dialogs 1.1
FontDialog {
    id: fontDialog
    title: "Please choose a font"
    font: Qt.font({ family: "Arial", pointSize: 24, weight: Font.Normal })
    onAccepted: {
        console.log("You chose: " + fontDialog.font)
        Qt.quit()
    }
    onRejected: {
        console.log("Canceled")
        Qt.quit()
    }
    Component.onCompleted: visible = true
}
					

A FontDialog window is automatically transient for its parent window. So whether you declare the dialog inside an Item or inside a Window , the dialog will appear centered over the window containing the item, or over the Window that you declared.

The implementation of FontDialog will be a platform font dialog if possible. If that isn't possible, then it will try to instantiate a QFontDialog . If that also isn't possible, then it will fall back to a QML implementation, DefaultFontDialog.qml. In that case you can customize the appearance by editing this file. DefaultFontDialog.qml contains a Rectangle to hold the dialog's contents, because certain embedded systems do not support multiple top-level windows. When the dialog becomes visible, it will automatically be wrapped in a Window if possible, or simply reparented on top of the main window if there can only be one window.

特性文档编制

currentFont : font

The font which the user selected.

该特性在 Qt 5.3 引入。

font : font

The font which the user selected and accepted.

modality : Qt::WindowModality

Whether the dialog should be shown modal with respect to the window containing the dialog's parent Item, modal with respect to the whole application, or non-modal.

By default it is Qt.NonModal .

Modality does not mean that there are any blocking calls to wait for the dialog to be accepted or rejected; it's only that the user will be prevented from interacting with the parent window and/or the application windows at the same time.

You probably need to write an onAccepted handler if you wish to change a font after the user has pressed the OK button, or an onCurrentFontChanged handler if you wish to react to every change the user makes while the dialog is open.

monospacedFonts : bool

Whether the dialog will show monospaced fonts or not.

nonScalableFonts : bool

Whether the dialog will show non scalable fonts or not.

proportionalFonts : bool

Whether the dialog will show proportional fonts or not.

scalableFonts : bool

Whether the dialog will show scalable fonts or not.

title : string

The title of the dialog window.

visible : bool

This property holds whether the dialog is visible. By default this is false.

另请参阅 modality .

方法文档编制

void close ()

Closes the dialog.

void open ()

Shows the dialog to the user. It is equivalent to setting visible to true.