A generic QtQuick dialog wrapper with standard buttons. 更多...
import 语句: | import QtQuick.Dialogs 1.3 |
Since: | Qt 5.3 |
The purpose of Dialog is to wrap arbitrary content into a dialog window including a row of platform-tailored buttons.
The
contentItem
is the default property (the only allowed child element), and items declared inside the Dialog will actually be children of another Item inside the
contentItem
. The row of
standardButtons
will also be inside
contentItem
below the declared content, and Dialog will attempt to size itself to fit the content and the buttons.
Alternatively it is possible to bind contentItem to a custom Item, in which case there will be no buttons, no margins, and the custom content will fill the whole dialog. This is much like creating a Window , except that on platforms which do not support showing multiple windows, the window borders will be simulated and it will be shown in same scene.
注意: do not attempt to bind the width or height of the dialog to the width or height of its content, because Dialog already tries to size itself to the content. If your goal is to change or eliminate the margins, you must override contentItem . If your goal is simply to show a window (whether modal or not), and your platform supports it, it is simpler to use Window 代替。
This property holds the button pressed by the user. Its value is one of the flags set for the standardButtons 特性。
The QML object which implements the dialog contents. Should be an Item .
For example the following dialog will show custom content and no buttons:
import QtQuick 2.3 import QtQuick.Controls 1.2 import QtQuick.Dialogs 1.2 Dialog { visible: true title: "Blue sky dialog" contentItem: Rectangle { color: "lightskyblue" implicitWidth: 400 implicitHeight: 100 Text { text: "Hello blue sky!" color: "navy" anchors.centerIn: parent } } }
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.WindowModal
.
Modality does not mean that there are any blocking calls to wait for the dialog to be accepted or rejected: only that the user will be prevented from interacting with the parent window or the application windows until the dialog is dismissed.
Dialog has a row of buttons along the bottom, each of which has a ButtonRole that determines which signal will be emitted when the button is pressed. You can also find out which specific button was pressed after the fact via the clickedButton property. You can control which buttons are available by setting standardButtons to a bitwise-or combination of the following flags:
常量 | 描述 |
---|---|
StandardButton.Ok
|
An OK button defined with the AcceptRole . |
StandardButton.Open
|
An 打开 button defined with the AcceptRole . |
StandardButton.Save
|
A Save button defined with the AcceptRole . |
StandardButton.Cancel
|
A Cancel button defined with the RejectRole . |
StandardButton.Close
|
A Close button defined with the RejectRole . |
StandardButton.Discard
|
A Discard or Don't Save button, depending on the platform, defined with the DestructiveRole . |
StandardButton.Apply
|
An Apply button defined with the ApplyRole . |
StandardButton.Reset
|
A Reset button defined with the ResetRole . |
StandardButton.RestoreDefaults
|
A Restore Defaults button defined with the ResetRole . |
StandardButton.Help
|
A 帮助 button defined with the HelpRole . |
StandardButton.SaveAll
|
A Save All button defined with the AcceptRole . |
StandardButton.Yes
|
A Yes button defined with the YesRole . |
StandardButton.YesToAll
|
A Yes to All button defined with the YesRole . |
StandardButton.No
|
A No button defined with the NoRole . |
StandardButton.NoToAll
|
A No to All button defined with the NoRole . |
StandardButton.Abort
|
An Abort button defined with the RejectRole . |
StandardButton.Retry
|
A Retry button defined with the AcceptRole . |
StandardButton.Ignore
|
An Ignore button defined with the AcceptRole . |
For example the following dialog will show a calendar with the ability to save or cancel a date:
import QtQuick 2.3 import QtQuick.Controls 1.2 import QtQuick.Dialogs 1.2 Dialog { id: dateDialog visible: true title: "Choose a date" standardButtons: StandardButton.Save | StandardButton.Cancel onAccepted: console.log("Saving the date " + calendar.selectedDate.toLocaleDateString()) Calendar { id: calendar onDoubleClicked: dateDialog.click(StandardButton.Save) } }
默认为
StandardButton.Ok
.
The enum values are the same as in QMessageBox::StandardButtons .
title : string |
The title of the dialog window.
visible : bool |
This property holds whether the dialog is visible. By default this is
false
.
另请参阅 modality .
This signal is emitted when the user has pressed any button which has the AcceptRole : OK , 打开 , Save , Save All , Retry or Ignore .
相应处理程序是
onAccepted
.
actionChosen ( var action ) |
This signal is emitted when the user has pressed any button or a key associated with some role (such as the Enter or Escape keys). The action parameter carries information about the event:
StandardButton.Ok
if accepted and
StandardButton.Cancel
if rejected.
0
if none
false
to stop the event from triggering its predefined action
By handling this signal and setting the
action.accepted
field to
false
, it's possible to implement some validation on the dialog contents before accepting it, for example.
相应处理程序是
onActionChosen
.
This signal was introduced in QtQuick.Controls 1.8.
This signal is emitted when the user has pressed the Apply button.
相应处理程序是
onApply
.
This signal is emitted when the user has pressed the Discard button.
相应处理程序是
onDiscard
.
This signal is emitted when the user has pressed the
帮助
button. Depending on platform, the dialog may not be automatically dismissed because the help that your application provides may need to be relevant to the text shown in this dialog in order to assist the user in making a decision. However on other platforms it's not possible to show a dialog and a help window at the same time. If you want to be sure that the dialog will close, you can set
visible
to
false
in your handler.
相应处理程序是
onHelp
.
This signal is emitted when the user has pressed any button which has the NoRole : No or No to All .
相应处理程序是
onNo
.
This signal is emitted when the user has dismissed the dialog, by closing the dialog window, by pressing a Cancel , Close or Abort button on the dialog, or by pressing the back button or the escape key.
相应处理程序是
onRejected
.
This signal is emitted when the user has pressed any button which has the ResetRole : Reset or Restore Defaults .
相应处理程序是
onReset
.
This signal is emitted when the user has pressed any button which has the YesRole : Yes or Yes to All .
相应处理程序是
onYes
.
Closes the dialog.
Shows the dialog to the user. It is equivalent to setting
visible
to
true
.