Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QDialogButtonBox Class

TheQDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the current widget style.More...

Header:#include <QDialogButtonBox>
Since: Qt 4.2
Inherits:QWidget

Public Types

enumButtonLayout { WinLayout, MacLayout, KdeLayout, GnomeLayout }
enumButtonRole { InvalidRole, AcceptRole, RejectRole, DestructiveRole, ..., ResetRole }
enumStandardButton { Ok, Open, Save, Cancel, ..., NoButton }
flagsStandardButtons

Properties

Public Functions

QDialogButtonBox(QWidget * parent = 0)
QDialogButtonBox(Qt::Orientation orientation, QWidget * parent = 0)
QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation = Qt::Horizontal, QWidget * parent = 0)
~QDialogButtonBox()
voidaddButton(QAbstractButton * button, ButtonRole role)
QPushButton *addButton(const QString & text, ButtonRole role)
QPushButton *addButton(StandardButton button)
QPushButton *button(StandardButton which) const
ButtonRolebuttonRole(QAbstractButton * button) const
QList<QAbstractButton *>buttons() const
boolcenterButtons() const
voidclear()
Qt::Orientationorientation() const
voidremoveButton(QAbstractButton * button)
voidsetCenterButtons(bool center)
voidsetOrientation(Qt::Orientation orientation)
voidsetStandardButtons(StandardButtons buttons)
StandardButtonstandardButton(QAbstractButton * button) const
StandardButtonsstandardButtons() const

Signals

voidaccepted()
voidclicked(QAbstractButton * button)
voidhelpRequested()
voidrejected()

Reimplemented Protected Functions

virtual voidchangeEvent(QEvent * event)
virtual boolevent(QEvent * event)
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Additional Inherited Members

  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject
  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice
  • 1 protected slot inherited fromQWidget

Detailed Description

TheQDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the current widget style.

Dialogs and message boxes typically present buttons in a layout that conforms to the interface guidelines for that platform. Invariably, different platforms have different layouts for their dialogs.QDialogButtonBox allows a developer to add buttons to it and will automatically use the appropriate layout for the user's desktop environment.

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 andCancel buttons). It is sometimes convenient to create these buttons in a standard way.

There are a couple ways of usingQDialogButtonBox. One ways is to create the buttons (or button texts) yourself and add them to the button box, specifying their role.

    findButton=newQPushButton(tr("&Find"));    findButton->setDefault(true);    moreButton=newQPushButton(tr("&More"));    moreButton->setCheckable(true);    moreButton->setAutoDefault(false);    buttonBox=newQDialogButtonBox(Qt::Vertical);    buttonBox->addButton(findButton,QDialogButtonBox::ActionRole);    buttonBox->addButton(moreButton,QDialogButtonBox::ActionRole);

Alternatively,QDialogButtonBox provides several standard buttons (e.g. OK, Cancel, Save) that you can use. They exist as flags so you can OR them together in the constructor.

    buttonBox=newQDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);    connect(buttonBox, SIGNAL(accepted()),this, SLOT(accept()));    connect(buttonBox, SIGNAL(rejected()),this, SLOT(reject()));

You can mix and match normal buttons and standard buttons.

Currently the buttons are laid out in the following way if the button box is horizontal:

GnomeLayout HorizontalButton box laid out in horizontalGnomeLayout
KdeLayout HorizontalButton box laid out in horizontalKdeLayout
MacLayout HorizontalButton box laid out in horizontalMacLayout
WinLayout HorizontalButton box laid out in horizontalWinLayout

The buttons are laid out the following way if the button box is vertical:

Additionally, button boxes that contain only buttons withActionRole orHelpRole can be considered modeless and have an alternate look on Mac OS X:

modeless horizontalMacLayoutScreenshot of modeless horizontal MacLayout

When a button is clicked in the button box, theclicked() signal is emitted for the actual button is that is pressed. For convenience, if the button has anAcceptRole,RejectRole, orHelpRole, theaccepted(),rejected(), orhelpRequested() signals are emitted respectively.

If you want a specific button to be default you need to callQPushButton::setDefault() on it yourself. However, if there is no default button set and to preserve which button is the default button across platforms when using theQPushButton::autoDefault property, the first push button with the accept role is made the default button when theQDialogButtonBox is shown,

See alsoQMessageBox,QPushButton, andQDialog.

Member Type Documentation

enum QDialogButtonBox::ButtonLayout

This enum describes the layout policy to be used when arranging the buttons contained in the button box.

ConstantValueDescription
QDialogButtonBox::WinLayout0Use a policy appropriate for applications on Windows.
QDialogButtonBox::MacLayout1Use a policy appropriate for applications on Mac OS X.
QDialogButtonBox::KdeLayout2Use a policy appropriate for applications on KDE.
QDialogButtonBox::GnomeLayout3Use a policy appropriate for applications on GNOME.

The button layout is specified by thecurrent style. However, on the X11 platform, it may be influenced by the desktop environment.

enum QDialogButtonBox::ButtonRole

This enum describes the roles that can be used to describe buttons in the button box. Combinations of these roles are as flags used to describe different aspects of their behavior.

ConstantValueDescription
QDialogButtonBox::InvalidRole-1The button is invalid.
QDialogButtonBox::AcceptRole0Clicking the button causes the dialog to be accepted (e.g. OK).
QDialogButtonBox::RejectRole1Clicking the button causes the dialog to be rejected (e.g. Cancel).
QDialogButtonBox::DestructiveRole2Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog.
QDialogButtonBox::ActionRole3Clicking the button causes changes to the elements within the dialog.
QDialogButtonBox::HelpRole4The button can be clicked to request help.
QDialogButtonBox::YesRole5The button is a "Yes"-like button.
QDialogButtonBox::NoRole6The button is a "No"-like button.
QDialogButtonBox::ApplyRole8The button applies current changes.
QDialogButtonBox::ResetRole7The button resets the dialog's fields to default values.

See alsoStandardButton.

enum QDialogButtonBox::StandardButton
flags QDialogButtonBox::StandardButtons

These enums describe flags for standard buttons. Each button has a definedButtonRole.

ConstantValueDescription
QDialogButtonBox::Ok0x00000400An "OK" button defined with theAcceptRole.
QDialogButtonBox::Open0x00002000A "Open" button defined with theAcceptRole.
QDialogButtonBox::Save0x00000800A "Save" button defined with theAcceptRole.
QDialogButtonBox::Cancel0x00400000A "Cancel" button defined with theRejectRole.
QDialogButtonBox::Close0x00200000A "Close" button defined with theRejectRole.
QDialogButtonBox::Discard0x00800000A "Discard" or "Don't Save" button, depending on the platform, defined with theDestructiveRole.
QDialogButtonBox::Apply0x02000000An "Apply" button defined with theApplyRole.
QDialogButtonBox::Reset0x04000000A "Reset" button defined with theResetRole.
QDialogButtonBox::RestoreDefaults0x08000000A "Restore Defaults" button defined with theResetRole.
QDialogButtonBox::Help0x01000000A "Help" button defined with theHelpRole.
QDialogButtonBox::SaveAll0x00001000A "Save All" button defined with theAcceptRole.
QDialogButtonBox::Yes0x00004000A "Yes" button defined with theYesRole.
QDialogButtonBox::YesToAll0x00008000A "Yes to All" button defined with theYesRole.
QDialogButtonBox::No0x00010000A "No" button defined with theNoRole.
QDialogButtonBox::NoToAll0x00020000A "No to All" button defined with theNoRole.
QDialogButtonBox::Abort0x00040000An "Abort" button defined with theRejectRole.
QDialogButtonBox::Retry0x00080000A "Retry" button defined with theAcceptRole.
QDialogButtonBox::Ignore0x00100000An "Ignore" button defined with theAcceptRole.
QDialogButtonBox::NoButton0x00000000An invalid button.

The StandardButtons type is a typedef forQFlags<StandardButton>. It stores an OR combination of StandardButton values.

See alsoButtonRole andstandardButtons.

Property Documentation

centerButtons :bool

This property holds whether the buttons in the button box are centered.

By default, this property is false. This behavior is appopriate for most types of dialogs. A notable exception is message boxes on most platforms (e.g. Windows), where the button box is centered horizontally.

Access functions:

boolcenterButtons() const
voidsetCenterButtons(bool center)

See alsoQMessageBox.

orientation :Qt::Orientation

This property holds the orientation of the button box.

By default, the orientation is horizontal (i.e. the buttons are laid out side by side). The possible orientations areQt::Horizontal andQt::Vertical.

Access functions:

Qt::Orientationorientation() const
voidsetOrientation(Qt::Orientation orientation)

standardButtons :StandardButtons

This property holds collection of standard buttons in the button box.

This property controls which standard buttons are used by the button box.

Access functions:

StandardButtonsstandardButtons() const
voidsetStandardButtons(StandardButtons buttons)

See alsoaddButton().

Member Function Documentation

QDialogButtonBox::QDialogButtonBox(QWidget * parent = 0)

Constructs an empty, horizontal button box with the givenparent.

See alsoorientation andaddButton().

QDialogButtonBox::QDialogButtonBox(Qt::Orientation orientation,QWidget * parent = 0)

Constructs an empty button box with the givenorientation andparent.

See alsoorientation andaddButton().

QDialogButtonBox::QDialogButtonBox(StandardButtons buttons,Qt::Orientation orientation = Qt::Horizontal,QWidget * parent = 0)

Constructs a button box with the givenorientation andparent, containing the standard buttons specified bybuttons.

See alsoorientation andaddButton().

QDialogButtonBox::~QDialogButtonBox()

Destroys the button box.

[signal]void QDialogButtonBox::accepted()

This signal is emitted when a button inside the button box is clicked, as long as it was defined with theAcceptRole orYesRole.

See alsorejected(),clicked(), andhelpRequested().

void QDialogButtonBox::addButton(QAbstractButton * button,ButtonRole role)

Adds the givenbutton to the button box with the specifiedrole. If the role is invalid, the button is not added.

If the button has already been added, it is removed and added again with the new role.

Note:The button box takes ownership of the button.

See alsoremoveButton() andclear().

QPushButton * QDialogButtonBox::addButton(constQString & text,ButtonRole role)

Creates a push button with the giventext, adds it to the button box for the specifiedrole, and returns the corresponding push button. Ifrole is invalid, no button is created, and zero is returned.

See alsoremoveButton() andclear().

QPushButton * QDialogButtonBox::addButton(StandardButton button)

Adds a standardbutton to the button box if it is valid to do so, and returns a push button. Ifbutton is invalid, it is not added to the button box, and zero is returned.

See alsoremoveButton() andclear().

QPushButton * QDialogButtonBox::button(StandardButton which) const

Returns theQPushButton corresponding to the standard buttonwhich, or 0 if the standard button doesn't exist in this button box.

See alsostandardButton(),standardButtons(), andbuttons().

ButtonRole QDialogButtonBox::buttonRole(QAbstractButton * button) const

Returns the button role for the specifiedbutton. This function returnsInvalidRole ifbutton is 0 or has not been added to the button box.

See alsobuttons() andaddButton().

QList<QAbstractButton *> QDialogButtonBox::buttons() const

Returns a list of all the buttons that have been added to the button box.

See alsobuttonRole(),addButton(), andremoveButton().

[virtual protected]void QDialogButtonBox::changeEvent(QEvent * event)

Reimplemented fromQWidget::changeEvent().

void QDialogButtonBox::clear()

Clears the button box, deleting all buttons within it.

See alsoremoveButton() andaddButton().

[signal]void QDialogButtonBox::clicked(QAbstractButton * button)

This signal is emitted when a button inside the button box is clicked. The specific button that was pressed is specified bybutton.

See alsoaccepted(),rejected(), andhelpRequested().

[virtual protected]bool QDialogButtonBox::event(QEvent * event)

Reimplemented fromQObject::event().

[signal]void QDialogButtonBox::helpRequested()

This signal is emitted when a button inside the button box is clicked, as long as it was defined with theHelpRole.

See alsoaccepted(),rejected(), andclicked().

[signal]void QDialogButtonBox::rejected()

This signal is emitted when a button inside the button box is clicked, as long as it was defined with theRejectRole orNoRole.

See alsoaccepted(),helpRequested(), andclicked().

void QDialogButtonBox::removeButton(QAbstractButton * button)

Removesbutton from the button box without deleting it and sets its parent to zero.

See alsoclear(),buttons(), andaddButton().

StandardButton QDialogButtonBox::standardButton(QAbstractButton * button) const

Returns the standard button enum value corresponding to the givenbutton, orNoButton if the givenbutton isn't a standard button.

See alsobutton(),buttons(), andstandardButtons().

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp