Qt 5.11 | Qt Quick Dialogs | QML Types | Dialog QML Type

Qt 5.11.3 Reference Documentation

# Dialog QML Type

A generic QtQuick dialog wrapper with standard buttons. More...

Import Statement: | import QtQuick.Dialogs 1.3
Since: | Qt 5.3

- List of all members, including inherited members

## Properties

- clickedButton : StandardButton
- contentItem : QObject
- modality : Qt::WindowModality
- standardButtons : StandardButtons
- title : string
- visible : bool

## Signals

- accepted()
- apply()
- discard()
- help()
- no()
- rejected()
- reset()
- yes()

## Methods

- void close()
- void open()

## Detailed Description

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.

Note: 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 instead.

## Property Documentation

clickedButton : StandardButton

This property holds the button pressed by the user. Its value is one of the flags set for the standardButtons property.

contentItem : QObject

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
              }
          }
      }

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

standardButtons : StandardButtons

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:

Constant | Description
--- | ---
`StandardButton.Ok` | An OK button defined with the AcceptRole.
`StandardButton.Open` | An Open 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 Help 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)
          }
      }

The default is `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`.

See also modality.

## Signal Documentation

accepted()

This signal is emitted when the user has pressed any button which has the AcceptRole: OK, Open, Save, Save All, Retry or Ignore.

The corresponding handler is `onAccepted`.

apply()

This signal is emitted when the user has pressed the Apply button.

The corresponding handler is `onApply`.

discard()

This signal is emitted when the user has pressed the Discard button.

The corresponding handler is `onDiscard`.

help()

This signal is emitted when the user has pressed the Help 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.

The corresponding handler is `onHelp`.

no()

This signal is emitted when the user has pressed any button which has the NoRole: No or No to All.

The corresponding handler is `onNo`.

rejected()

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.

The corresponding handler is `onRejected`.

reset()

This signal is emitted when the user has pressed any button which has the ResetRole: Reset or Restore Defaults.

The corresponding handler is `onReset`.

yes()

This signal is emitted when the user has pressed any button which has the YesRole: Yes or Yes to All.

The corresponding handler is `onYes`.

## Method Documentation

void close()

Closes the dialog.

void open()

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