Dialog QML Type

Popup dialog with standard buttons and a title, used for short-term interaction with the user. More...

Import Statement: import QtQuick.Controls 2.15
Since: Qt 5.8
Inherits:

Popup

Properties

Signals

Methods

Detailed Description

A dialog is a popup mostly used for short-term tasks and brief communications with the user. Similarly to ApplicationWindow and Page, Dialog is organized into three sections: header, contentItem, and footer.

Dialog Title and Buttons

Dialog's title is displayed by a style-specific title bar that is assigned as a dialog header by default.

Dialog's standard buttons are managed by a DialogButtonBox that is assigned as a dialog footer by default. The dialog's standardButtons property is forwarded to the respective property of the button box. Furthermore, the accepted() and rejected() signals of the button box are connected to the respective signals in Dialog.

 Dialog {
     id: dialog
     title: "Title"
     standardButtons: Dialog.Ok | Dialog.Cancel

     onAccepted: console.log("Ok clicked")
     onRejected: console.log("Cancel clicked")
 }

A modal dialog blocks input to other content beneath the dialog. When a modal dialog is opened, the user must finish interacting with the dialog and close it before they can access any other content in the same window.

 Dialog {
     id: dialog
     modal: true
     standardButtons: Dialog.Ok
 }

Modeless Dialogs

A modeless dialog is a dialog that operates independently of other content around the dialog. When a modeless dialog is opened, the user is allowed to interact with both the dialog and the other content in the same window.

 Dialog {
     id: dialog
     modal: false
     standardButtons: Dialog.Ok
 }

See also DialogButtonBox and Popup Controls.

Property Documentation

This property holds the dialog footer item. The footer item is positioned to the bottom, and resized to the width of the dialog. The default value is null.

Note: Assigning a DialogButtonBox as a dialog footer automatically connects its accepted() and rejected() signals to the respective signals in Dialog.

Note: Assigning a DialogButtonBox, ToolBar, or TabBar as a dialog footer automatically sets the respective DialogButtonBox::position, ToolBar::position, or TabBar::position property to Footer.

See also header.


header : Item

This property holds the dialog header item. The header item is positioned to the top, and resized to the width of the dialog. The default value is null.

Note: Assigning a DialogButtonBox as a dialog header automatically connects its accepted() and rejected() signals to the respective signals in Dialog.

Note: Assigning a DialogButtonBox, ToolBar, or TabBar as a dialog header automatically sets the respective DialogButtonBox::position, ToolBar::position, or TabBar::position property to Header.

See also footer.


[read-only] implicitFooterHeight : real

This property holds the implicit footer height.

The value is equal to footer && footer.visible ? footer.implicitHeight : 0.

This property was introduced in QtQuick.Controls 2.5 (Qt 5.12).

See also implicitFooterWidth and implicitHeaderHeight.


[read-only] implicitFooterWidth : real

This property holds the implicit footer width.

The value is equal to footer && footer.visible ? footer.implicitWidth : 0.

This property was introduced in QtQuick.Controls 2.5 (Qt 5.12).

See also implicitFooterHeight and implicitHeaderWidth.


[read-only] implicitHeaderHeight : real

This property holds the implicit header height.

The value is equal to header && header.visible ? header.implicitHeight : 0.

This property was introduced in QtQuick.Controls 2.5 (Qt 5.12).

See also implicitHeaderWidth and implicitFooterHeight.


[read-only] implicitHeaderWidth : real

This property holds the implicit header width.

The value is equal to header && header.visible ? header.implicitWidth : 0.

This property was introduced in QtQuick.Controls 2.5 (Qt 5.12).

See also implicitHeaderHeight and implicitFooterWidth.


result : int

This property holds the result code.

Standard result codes:

ConstantDescription
Dialog.AcceptedThe dialog was accepted.
Dialog.RejectedThe dialog was rejected.

This property was introduced in QtQuick.Controls 2.3 (Qt 5.10).

See also accept(), reject(), and done().


standardButtons : enumeration

This property holds a combination of standard buttons that are used by the dialog.

 Dialog {
     id: dialog
     title: "Title"
     standardButtons: Dialog.Ok | Dialog.Cancel

     onAccepted: console.log("Ok clicked")
     onRejected: console.log("Cancel clicked")
 }

The buttons will be positioned in the appropriate order for the user's platform.

Possible flags:

ConstantDescription
Dialog.OkAn "OK" button defined with the AcceptRole.
Dialog.OpenAn "Open" button defined with the AcceptRole.
Dialog.SaveA "Save" button defined with the AcceptRole.
Dialog.CancelA "Cancel" button defined with the RejectRole.
Dialog.CloseA "Close" button defined with the RejectRole.
Dialog.DiscardA "Discard" or "Don't Save" button, depending on the platform, defined with the DestructiveRole.
Dialog.ApplyAn "Apply" button defined with the ApplyRole.
Dialog.ResetA "Reset" button defined with the ResetRole.
Dialog.RestoreDefaultsA "Restore Defaults" button defined with the ResetRole.
Dialog.HelpA "Help" button defined with the HelpRole.
Dialog.SaveAllA "Save All" button defined with the AcceptRole.
Dialog.YesA "Yes" button defined with the YesRole.
Dialog.YesToAllA "Yes to All" button defined with the YesRole.
Dialog.NoA "No" button defined with the NoRole.
Dialog.NoToAllA "No to All" button defined with the NoRole.
Dialog.AbortAn "Abort" button defined with the RejectRole.
Dialog.RetryA "Retry" button defined with the AcceptRole.
Dialog.IgnoreAn "Ignore" button defined with the AcceptRole.
Dialog.NoButtonAn invalid button.

See also DialogButtonBox.


title : string

This property holds the dialog title.

The title is displayed in the dialog header.

 Dialog {
     title: qsTr("About")

     Label {
         text: "Lorem ipsum..."
     }
 }

Signal Documentation

accepted()

This signal is emitted when the dialog has been accepted either interactively or by calling accept().

Note: This signal is not emitted when closing the dialog with close() or setting visible to false.

Note: The corresponding handler is onAccepted.

See also rejected().


applied()

This signal is emitted when the Dialog.Apply standard button is clicked.

Note: The corresponding handler is onApplied.

This signal was introduced in QtQuick.Controls 2.3 (Qt 5.10).

See also discarded() and reset().


discarded()

This signal is emitted when the Dialog.Discard standard button is clicked.

Note: The corresponding handler is onDiscarded.

This signal was introduced in QtQuick.Controls 2.3 (Qt 5.10).

See also reset() and applied().


helpRequested()

This signal is emitted when the Dialog.Help standard button is clicked.

Note: The corresponding handler is onHelpRequested.

This signal was introduced in QtQuick.Controls 2.3 (Qt 5.10).

See also accepted() and rejected().


rejected()

This signal is emitted when the dialog has been rejected either interactively or by calling reject().

Note: This signal is not emitted when closing the dialog with close() or setting visible to false.

Note: The corresponding handler is onRejected.

See also accepted().


reset()

This signal is emitted when the Dialog.Reset standard button is clicked.

Note: The corresponding handler is onReset.

This signal was introduced in QtQuick.Controls 2.3 (Qt 5.10).

See also discarded() and applied().


Method Documentation

void accept()

Closes the dialog and emits the accepted() signal.

See also reject() and done().


void done(int result)

Closes the dialog, sets the result, and emits accepted() or rejected() depending on whether the result is Dialog.Accepted or Dialog.Rejected, respectively.

This method was introduced in QtQuick.Controls 2.3 (Qt 5.10).

See also accept(), reject(), and result.


void reject()

Closes the dialog and emits the rejected() signal.

See also accept() and done().


AbstractButton standardButton(StandardButton button)

Returns the specified standard button, or null if it does not exist.

This method was introduced in QtQuick.Controls 2.3 (Qt 5.10).

See also standardButtons.