Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickdialogbuttonbox.cpp File Reference

(2451ff25a531a2427825726f4b5f015fb01d2663)

#include "qquickdialogbuttonbox_p.h"
#include "qquickdialogbuttonbox_p_p.h"
#include "qquickabstractbutton_p.h"
#include "qquickbutton_p.h"
#include "qquickdialog_p_p.h"
#include <QtCore/qpointer.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformtheme.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcontext.h>
#include <QtQml/qqmlcomponent.h>
#include <algorithm>
#include "moc_qquickdialogbuttonbox_p.cpp"
+ Include dependency graph for qquickdialogbuttonbox.cpp:

Go to the source code of this file.

Functions

static QT_BEGIN_NAMESPACE QPlatformDialogHelper::ButtonLayout platformButtonLayout ()
 A button box used in dialogs.
 
static QRectF alignedRect (Qt::LayoutDirection direction, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle)
 

Function Documentation

◆ alignedRect()

static QRectF alignedRect ( Qt::LayoutDirection direction,
Qt::Alignment alignment,
const QSizeF & size,
const QRectF & rectangle )
static

Definition at line 186 of file qquickdialogbuttonbox.cpp.

References Qt::AlignBottom, Qt::AlignHCenter, alignment, Qt::AlignRight, Qt::AlignVCenter, Qt::AlignVertical_Mask, direction, QRectF::size(), QGuiApplicationPrivate::visualAlignment(), QRectF::x(), and QRectF::y().

+ Here is the call graph for this function:

◆ platformButtonLayout()

static QT_BEGIN_NAMESPACE QPlatformDialogHelper::ButtonLayout platformButtonLayout ( )
static

A button box used in dialogs.

\qmltype DialogButtonBox
\inherits Container

! \instantiates QQuickDialogButtonBox \inqmlmodule QtQuick.Controls

Since
5.8

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:

\list

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

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. \uicontrol OK and \uicontrol 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. \uicontrol OK, \uicontrol Cancel, \uicontrol 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 \l 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:

\table \header

  • Role
  • Signal \row
  • AcceptRole, YesRole
  • \l accepted() \row
  • ApplyRole
  • \l applied() \row
  • DiscardRole
  • \l discarded() \row
  • HelpRole
  • \l helpRequested() \row
  • RejectRole, NoRole
  • \l rejected() \row
  • ResetRole
  • \l reset() \endtable
See also
Dialog

\qmlsignal QtQuick.Controls::DialogButtonBox::accepted()

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

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

\qmlsignal QtQuick.Controls::DialogButtonBox::rejected()

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

See also
accepted(), helpRequested(), clicked()
Since
QtQuick.Controls 2.3 (Qt 5.10) \qmlsignal QtQuick.Controls::DialogButtonBox::applied()

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

See also
discarded(), reset()
Since
QtQuick.Controls 2.3 (Qt 5.10) \qmlsignal QtQuick.Controls::DialogButtonBox::reset()

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

See also
discarded(), applied()
Since
QtQuick.Controls 2.3 (Qt 5.10) \qmlsignal QtQuick.Controls::DialogButtonBox::discarded()

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

See also
reset(), applied()

\qmlsignal QtQuick.Controls::DialogButtonBox::helpRequested()

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

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

\qmlsignal QtQuick.Controls::DialogButtonBox::clicked(AbstractButton button)

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

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

Definition at line 162 of file qquickdialogbuttonbox.cpp.

References QPlatformTheme::DialogButtonBoxLayout, and QGuiApplicationPrivate::platformTheme().

Referenced by QQuickDialogButtonBox::QQuickDialogButtonBox(), and QQuickDialogButtonBox::resetButtonLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: