Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QDialogButtonBox Class Reference
[QtGui module]

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

 #include <QDialogButtonBox>

Inherits QWidget.

This class was introduced in Qt 4.2.

Public Types

Properties

  • 57 properties inherited from QWidget
  • 1 property inherited from QObject

Public Functions

  • 206 public functions inherited from QWidget
  • 29 public functions inherited from QObject
  • 14 public functions inherited from QPaintDevice

Signals

Additional Inherited Members

  • 19 public slots inherited from QWidget
  • 1 public slot inherited from QObject
  • 4 static public members inherited from QWidget
  • 5 static public members inherited from QObject
  • 38 protected functions inherited from QWidget
  • 7 protected functions inherited from QObject
  • 1 protected function inherited from QPaintDevice
  • 1 protected slot inherited from QWidget

Detailed Description

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

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

     findButton = new QPushButton(tr("&Find"));
     findButton->setDefault(true);

     moreButton = new QPushButton(tr("&More"));
     moreButton->setCheckable(true);
     moreButton->setAutoDefault(false);

     buttonBox = new QDialogButtonBox(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 = new QDialogButtonBox(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 horizontal GnomeLayout
KdeLayout HorizontalButton box laid out in horizontal KdeLayout
MacLayout HorizontalButton box laid out in horizontal MacLayout
WinLayout HorizontalButton box laid out in horizontal WinLayout

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

GnomeLayout VerticalButton box laid out in vertical GnomeLayout
KdeLayout VerticalButton box laid out in vertical KdeLayout
MacLayout VerticalButton box laid out in vertical MacLayout
WinLayout VerticalButton box laid out in vertical WinLayout

Additionally, button boxes that contain only buttons with ActionRole or HelpRole can be considered modeless and have an alternate look on the mac:

Screenshot of modeless horizontal MacLayoutmodeless horizontal MacLayout
Screenshot of modeless vertical MacLayoutmodeless vertical MacLayout

When a button is clicked in the button box, the clicked() signal is emitted for the actual button is that is pressed. For convenience, if the button has an AcceptRole, RejectRole, or HelpRole, the accepted(), rejected(), or helpRequested() signals are emitted respectively.

If you want a specific button to be default you need to call QPushButton::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 the QPushButton::autoDefault property, the first push button with the accept role is made the default button when the QDialogButtonBox is shown,

See also QMessageBox, QPushButton, and QDialog.


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 the current style.

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

enum QDialogButtonBox::StandardButton
flags QDialogButtonBox::StandardButtons

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

ConstantValueDescription
QDialogButtonBox::Ok0x00000400An "OK" button defined with the AcceptRole.
QDialogButtonBox::Open0x00002000A "Open" button defined with the AcceptRole.
QDialogButtonBox::Save0x00000800A "Save" button defined with the AcceptRole.
QDialogButtonBox::Cancel0x00400000A "Cancel" button defined with the RejectRole.
QDialogButtonBox::Close0x00200000A "Close" button defined with the RejectRole.
QDialogButtonBox::Discard0x00800000A "Discard" or "Don't Save" button, depending on the platform, defined with the DestructiveRole.
QDialogButtonBox::Apply0x02000000An "Apply" button defined with the ApplyRole.
QDialogButtonBox::Reset0x04000000A "Reset" button defined with the ResetRole.
QDialogButtonBox::RestoreDefaults0x08000000A "Restore Defaults" button defined with the ResetRole.
QDialogButtonBox::Help0x01000000A "Help" button defined with the HelpRole.
QDialogButtonBox::SaveAll0x00001000A "Save All" button defined with the AcceptRole.
QDialogButtonBox::Yes0x00004000A "Yes" button defined with the YesRole.
QDialogButtonBox::YesToAll0x00008000A "Yes to All" button defined with the YesRole.
QDialogButtonBox::No0x00010000A "No" button defined with the NoRole.
QDialogButtonBox::NoToAll0x00020000A "No to All" button defined with the NoRole.
QDialogButtonBox::Abort0x00040000An "Abort" button defined with the RejectRole.
QDialogButtonBox::Retry0x00080000A "Retry" button defined with the AcceptRole.
QDialogButtonBox::Ignore0x00100000An "Ignore" button defined with the AcceptRole.
QDialogButtonBox::NoButton0x00000000An invalid button.

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

See also ButtonRole and standardButtons.


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:

  • bool centerButtons () const
  • void setCenterButtons ( bool center )

See also QMessageBox.

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 are Qt::Horizontal and Qt::Vertical.

Access functions:

  • Qt::Orientation orientation () const
  • void setOrientation ( 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:

  • StandardButtons standardButtons () const
  • void setStandardButtons ( StandardButtons buttons )

See also addButton().


Member Function Documentation

QDialogButtonBox::QDialogButtonBox ( QWidget * parent = 0 )

Constructs an empty, horizontal button box with the given parent.

See also orientation and addButton().

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

Constructs an empty button box with the given orientation and parent.

See also orientation and addButton().

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

Constructs a button box with the given orientation and parent, containing the standard buttons specified by buttons.

See also orientation and addButton().

QDialogButtonBox::~QDialogButtonBox ()

Destroys the button box.

void QDialogButtonBox::accepted ()   [signal]

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

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

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

Adds the given button to the button box with the specified role. 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.

See also removeButton() and clear().

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

This is an overloaded member function, provided for convenience.

Creates a push button with the given text, adds it to the button box for the specified role, and returns the corresponding push button. If role is invalid, no button is created, and zero is returned.

See also removeButton() and clear().

QPushButton * QDialogButtonBox::addButton ( StandardButton button )

This is an overloaded member function, provided for convenience.

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

See also removeButton() and clear().

QPushButton * QDialogButtonBox::button ( StandardButton which ) const

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

See also standardButton(), standardButtons(), and buttons().

ButtonRole QDialogButtonBox::buttonRole ( QAbstractButton * button ) const

Returns the button role for the specified button. This function returns InvalidRole if button is 0 or has not been added to the button box.

See also buttons() and addButton().

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

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

See also buttonRole(), addButton(), and removeButton().

void QDialogButtonBox::clear ()

Clears the button box, deleting all buttons within it.

See also removeButton() and addButton().

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

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

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

void QDialogButtonBox::helpRequested ()   [signal]

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

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

void QDialogButtonBox::rejected ()   [signal]

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

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

void QDialogButtonBox::removeButton ( QAbstractButton * button )

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

See also clear(), buttons(), and addButton().

StandardButton QDialogButtonBox::standardButton ( QAbstractButton * button ) const

Returns the standard button enum value corresponding to the given button, or NoButton if the given button isn't a standard button.

See also button(), buttons(), and standardButtons().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 17
  4. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Labs au hasard

Logo

QMake et au-delà

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtextended4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web