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  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QAbstractButton Class Reference
[QtGui module]

The QAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons. More...

#include <QAbstractButton>

Inherits QWidget.

Inherited by Q3Button, QCheckBox, QPushButton, QRadioButton, and QToolButton.

Properties

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

Public Functions

  • 184 public functions inherited from QWidget
  • 28 public functions inherited from QObject
  • 10 public functions inherited from QPaintDevice

Public Slots

  • 17 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

Protected Functions

  • 39 protected functions inherited from QWidget
  • 7 protected functions inherited from QObject

Additional Inherited Members

  • 4 static public members inherited from QWidget
  • 4 static public members inherited from QObject

Detailed Description

The QAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons.

This class implements an abstract button. Subclasses of this class handle user actions, and specify how the button is drawn.

QAbstractButton provides support for both push buttons and checkable (toggle) buttons. Checkable buttons are implemented in the QRadioButton and QCheckBox classes. Push buttons are implemented in the QPushButton and QToolButton classes; these also provide toggle behavior if required.

Any button can display a label containing text and an icon. setText() sets the text; setIcon() sets the icon. If a button is disabled, its label is changed to give the button a "disabled" appearance.

If the button is a text button with a string containing an ampersand (&), QAbstractButton creates an automatic shortcut key, called a mnemonic, that may change based on the button translation. The following code creates a push button labelled "Rock & Roll" (where the c is underlined):

    QPushButton *button = new QPushButton(tr("Ro&ck && Roll"), this);

In this example, the shortcut Alt+C is assigned to the button, so that when the user presses Alt+C the button will call animateClick().

You can also set a custom shortcut key using the setShortcut() function. This is useful mostly for buttons that do not have any text, because they have no automatic shortcut.

      button->setPixmap(QPixmap(":/images/print.png"));
      button->setShortcut(tr("Alt+F7"));

All of the buttons provided by Qt (QPushButton, QToolButton, QCheckBox, and QRadioButton) can display both text and pixmaps.

A button can be made the default button in a dialog are provided by QPushButton::setDefault() and QPushButton::setAutoDefault().

QAbstractButton provides most of the states used for buttons:

  • isDown() indicates whether the button is pressed down.
  • isChecked() indicates whether the button is checked. Only checkable buttons can be checked and unchecked (see below).
  • isEnabled() indicates whether the button can be pressed by the user.
  • setAutoRepeat() sets whether the button will auto-repeat if the user holds it down.
  • setCheckable() sets whether the button is a toggle button or not.

The difference between isDown() and isChecked() is as follows. When the user clicks a toggle button to check it, the button is first pressed then released into the checked state. When the user clicks it again (to uncheck it), the button moves first to the pressed state, then to the unchecked state (isChecked() and isDown() are both false).

QAbstractButton provides five signals:

  1. pressed() is emitted when the left mouse button is pressed while the mouse cursor is inside the button.
  2. released() is emitted when the left mouse button is released.
  3. clicked() is emitted when the button is first pressed and then released when the shortcut key is typed, or when animateClick() is called.
  4. toggled(bool) is emitted when the state of a toggle button changes.

To subclass QAbstractButton, you must reimplement at least paintEvent() to draw the button's outline and its text or pixmap. It is generally advisable to reimplement sizeHint() as well, and sometimes hitButton() (to determine whether a button press is within the button). For buttons with more than two states (like tri-state buttons), you will also have to reimplement checkStateSet() and nextCheckState().

See also QButtonGroup.


Property Documentation

autoExclusive : bool

This property holds whether auto-exclusivity is enabled.

If auto-exclusivity is enabled, checkable buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. In an exclusive button group, only one button can be checked at any time; checking another button automatically unchecks the previously checked one.

The property has no effect on buttons that belong to a button group.

autoExclusive is off by default, except for radio buttons.

Access functions:

  • bool autoExclusive () const
  • void setAutoExclusive ( bool )

See also QRadioButton.

autoRepeat : bool

This property holds whether autoRepeat is enabled.

If autoRepeat is enabled then the clicked() signal is emitted at regular intervals when the button is down. This property has no effect on toggle buttons. autoRepeat is off by default.

Access functions:

  • bool autoRepeat () const
  • void setAutoRepeat ( bool )

checkable : bool

This property holds whether the button is checkable.

By default, the button is not checkable.

Access functions:

  • bool isCheckable () const
  • void setCheckable ( bool )

See also checked.

checked : bool

This property holds whether the button is checked.

Only checkable buttons can be checked. By default, the button is unchecked.

Access functions:

  • bool isChecked () const
  • void setChecked ( bool )

See also checkable.

down : bool

This property holds whether the button is pressed down.

If this property is true, the button is pressed down. The signals pressed() and clicked() are not emitted if you set this property to true. The default is false.

Access functions:

  • bool isDown () const
  • void setDown ( bool )

icon : QIcon

This property holds the icon shown on the button.

The icon's default size is defined by the GUI style, but can be adjusted by setting the iconSize property.

Access functions:

  • QIcon icon () const
  • void setIcon ( const QIcon & icon )

iconSize : QSize

This property holds the icon size used for this button.

The default size is defined by the GUI style.

Access functions:

  • QSize iconSize () const
  • void setIconSize ( const QSize & size )

shortcut : QKeySequence

This property holds the mnemonic associated with the button.

Access functions:

  • QKeySequence shortcut () const
  • void setShortcut ( const QKeySequence & key )

text : QString

This property holds the text shown on the button.

This property will return a an empty string if the button has no text. If the text contains an ampersand character (&), a mnemonic is automatically created for it. The character that follows the '&' will be used as the shortcut key. Any previous mnemonic will be overwritten, or cleared if no mnemonic is defined by the text.

There is no default text.

Access functions:

  • QString text () const
  • void setText ( const QString & text )

Member Function Documentation

QAbstractButton::QAbstractButton ( QWidget * parent = 0 )

Constructs an abstract button with a parent.

QAbstractButton::~QAbstractButton ()

Destroys the button.

void QAbstractButton::animateClick ( int msec = 100 )   [slot]

Performs an animated click: the button is pressed and released msec milliseconds later (the default is 100 msecs).

All signals associated with a click are emitted as appropriate.

This function does nothing if the button is disabled.

See also click().

void QAbstractButton::checkStateSet ()   [virtual protected]

This virtual handler is called when setChecked() was called, unless it was called from within nextCheckState(). It allows subclasses to reset their intermediate button states.

See also nextCheckState().

void QAbstractButton::click ()   [slot]

Performs a click.

All the usual signals associated with a click are emitted as appropriate. If the button is checkable, the state of the button is toggled.

This function does nothing if the button is disabled.

See also animateClick().

void QAbstractButton::clicked ( bool checked = false )   [signal]

This signal is emitted when the button is activated (i.e. pressed down then released while the mouse cursor is inside the button), when the shortcut key is typed, or when click() or animateClick() is called. Notably, this signal is not emitted if you call setDown(), setChecked() or toggle().

If the button is checkable, checked is true if the button is checked, or false if the button is unchecked.

See also pressed(), released(), and toggled().

QButtonGroup * QAbstractButton::group () const

Returns the group that this button belongs to.

If the button is not a member of any QButtonGroup, this function returns 0.

See also QButtonGroup.

bool QAbstractButton::hitButton ( const QPoint & pos ) const   [virtual protected]

Returns true if pos is inside the clickable button rectangle; otherwise returns false.

By default, the clickable area is the entire widget. Subclasses may reimplement this function to provide support for clickable areas of different shapes and sizes.

void QAbstractButton::nextCheckState ()   [virtual protected]

This virtual handler is called when a button is clicked. The default implementation calls setChecked(!isChecked()) if the button isCheckable(). It allows subclasses to implement intermediate button states.

See also checkStateSet().

void QAbstractButton::pressed ()   [signal]

This signal is emitted when the button is pressed down.

See also released() and clicked().

void QAbstractButton::released ()   [signal]

This signal is emitted when the button is released.

See also pressed(), clicked(), and toggled().

void QAbstractButton::toggle ()   [slot]

Toggles the state of a checkable button.

See also checked.

void QAbstractButton::toggled ( bool checked )   [signal]

This signal is emitted whenever a checkable button changes its state. checked is true if the button is checked, or false if the button is unchecked.

This may be the result of a user action, click() slot activation, or because setChecked() was called.

See also checked and clicked().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 53
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. 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
  4. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. 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 4.0
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