DialogButtonBox QML Type

A button box used in dialogs. More...

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

Container

Properties

Attached Properties

Signals

Methods

Detailed Description

Dialogs and message boxes typically present buttons in an order that conforms to the interface guidelines for that platform. Invariably, different platforms have their dialog buttons in different orders. DialogButtonBox allows a developer to add buttons to it and will automatically use the appropriate order for the user's platform.

Most buttons for a dialog follow certain roles. Such roles include:

  • Accepting or rejecting the dialog.
  • Asking for help.
  • Performing actions on the dialog itself (such as resetting fields or applying changes).

There can also be alternate ways of dismissing the dialog which may cause destructive results.

Most dialogs have buttons that can almost be considered standard (e.g. OK and Cancel buttons). It is sometimes convenient to create these buttons in a standard way.

There are a couple ways of using DialogButtonBox. One way is to specify the standard buttons (e.g. OK, Cancel, Save) and let the button box setup the buttons.

DialogButtonBox {
    standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel

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

Alternatively, buttons and their roles can be specified by hand:

DialogButtonBox {
    Button {
        text: qsTr("Save")
        DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
    }
    Button {
        text: qsTr("Close")
        DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole
    }
}

You can also mix and match normal buttons and standard buttons.

When a button is clicked in the button box, the clicked() signal is emitted for the actual button that is pressed. In addition, the following signals are automatically emitted when a button with the respective role(s) is pressed:

RoleSignal
AcceptRole, YesRoleaccepted()
ApplyRoleapplied()
DiscardRolediscarded()
HelpRolehelpRequested()
RejectRole, NoRolerejected()
ResetRolereset()

See also Dialog.

Property Documentation

alignment : flags

This property holds the alignment of the buttons.

Possible values:

ConstantDescription
undefinedThe buttons are resized to fill the available space.
Qt.AlignLeftThe buttons are aligned to the left.
Qt.AlignHCenterThe buttons are horizontally centered.
Qt.AlignRightThe buttons are aligned to the right.
Qt.AlignTopThe buttons are aligned to the top.
Qt.AlignVCenterThe buttons are vertically centered.
Qt.AlignBottomThe buttons are aligned to the bottom.

buttonLayout : enumeration

This property holds the button layout policy to be used when arranging the buttons contained in the button box. The default value is platform-specific.

Available values:

ConstantDescription
DialogButtonBox.WinLayoutUse a policy appropriate for applications on Windows.
DialogButtonBox.MacLayoutUse a policy appropriate for applications on macOS.
DialogButtonBox.KdeLayoutUse a policy appropriate for applications on KDE.
DialogButtonBox.GnomeLayoutUse a policy appropriate for applications on GNOME.
DialogButtonBox.AndroidLayoutUse a policy appropriate for applications on Android.

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


delegate : Component

This property holds a delegate for creating standard buttons.

See also standardButtons.


position : enumeration

This property holds the position of the button box.

Note: If the button box is assigned as a header or footer of ApplicationWindow or Page, the appropriate position is set automatically.

Possible values:

ConstantDescription
DialogButtonBox.HeaderThe button box is at the top, as a window or page header.
DialogButtonBox.FooterThe button box is at the bottom, as a window or page header.

The default value is Footer.

See also Dialog::header and Dialog::footer.


standardButtons : enumeration

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

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

See also standardButton().


Attached Property Documentation

[read-only] DialogButtonBox.buttonBox : DialogButtonBox

This attached property holds the button box that manages this button, or null if the button is not in a button box.


DialogButtonBox.buttonRole : enumeration

This attached property holds the role of each button in a button box.

DialogButtonBox {
    Button {
        text: qsTr("Save")
        DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
    }
    Button {
        text: qsTr("Close")
        DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole
    }
}

Available values:

ConstantDescription
DialogButtonBox.InvalidRoleThe button is invalid.
DialogButtonBox.AcceptRoleClicking the button causes the dialog to be accepted (e.g. OK).
DialogButtonBox.RejectRoleClicking the button causes the dialog to be rejected (e.g. Cancel).
DialogButtonBox.DestructiveRoleClicking the button causes a destructive change (e.g. for discarding changes) and closes the dialog.
DialogButtonBox.ActionRoleClicking the button causes changes to the elements within the dialog.
DialogButtonBox.HelpRoleThe button can be clicked to request help.
DialogButtonBox.YesRoleThe button is a "Yes"-like button.
DialogButtonBox.NoRoleThe button is a "No"-like button.
DialogButtonBox.ResetRoleThe button resets the dialog's fields to default values.
DialogButtonBox.ApplyRoleThe button applies current changes.

Signal Documentation

accepted()

This signal is emitted when a button defined with the AcceptRole or YesRole is clicked.

See also rejected(), clicked(), and helpRequested().


applied()

This signal is emitted when a button defined with the ApplyRole is clicked.

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

See also discarded() and reset().


clicked(button)

This signal is emitted when a button inside the button box is clicked.

See also accepted(), rejected(), and helpRequested().


discarded()

This signal is emitted when a button defined with the DiscardRole is clicked.

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

See also reset() and applied().


helpRequested()

This signal is emitted when a button defined with the HelpRole is clicked.

See also accepted(), rejected(), and clicked().


rejected()

This signal is emitted when a button defined with the RejectRole or NoRole is clicked.

See also accepted(), helpRequested(), and clicked().


reset()

This signal is emitted when a button defined with the ResetRole is clicked.

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

See also discarded() and applied().


Method Documentation

AbstractButton standardButton(button)

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

See also standardButtons.


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