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  · 

QCheckBox Class Reference

The QCheckBox widget provides a checkbox with a text label. More...

 #include <QCheckBox>

Inherits: QAbstractButton.

Properties

Public Functions

QCheckBox ( QWidget * parent = 0 )
QCheckBox ( const QString & text, QWidget * parent = 0 )
Qt::CheckState checkState () const
bool isTristate () const
void setCheckState ( Qt::CheckState state )
void setTristate ( bool y = true )

Reimplemented Public Functions

virtual QSize sizeHint () const

Signals

void stateChanged ( int state )

Protected Functions

void initStyleOption ( QStyleOptionButton * option ) const

Reimplemented Protected Functions

virtual void checkStateSet ()
virtual bool event ( QEvent * e )
virtual bool hitButton ( const QPoint & pos ) const
virtual void mouseMoveEvent ( QMouseEvent * e )
virtual void nextCheckState ()
virtual void paintEvent ( QPaintEvent * )

Additional Inherited Members

  • 5 public slots inherited from QAbstractButton
  • 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
  • 1 protected slot inherited from QWidget

Detailed Description

The QCheckBox widget provides a checkbox with a text label.

A QCheckBox is an option button that can be switched on (checked) or off (unchecked). Checkboxes are typically used to represent features in an application that can be enabled or disabled without affecting others, but different types of behavior can be implemented. For example, a QButtonGroup can be used to group check buttons logically, allowing exclusive checkboxes. However, QButtonGroup does not provide any visual representation.

The image below further illustrates the differences between exclusive and non-exclusive checkboxes.

Whenever a checkbox is checked or cleared it emits the signal stateChanged(). Connect to this signal if you want to trigger an action each time the checkbox changes state. You can use isChecked() to query whether or not a checkbox is checked.

In addition to the usual checked and unchecked states, QCheckBox optionally provides a third state to indicate "no change". This is useful whenever you need to give the user the option of neither checking nor unchecking a checkbox. If you need this third state, enable it with setTristate(), and use checkState() to query the current toggle state.

Just like QPushButton, a checkbox displays text, and optionally a small icon. The icon is set with setIcon(). The text can be set in the constructor or with setText(). A shortcut key can be specified by preceding the preferred character with an ampersand. For example:

 QCheckBox *checkbox = new QCheckBox("C&ase sensitive", this);

In this example the shortcut is Alt+A. See the QShortcut documentation for details (to display an actual ampersand, use '&&').

Important inherited functions: text(), setText(), text(), pixmap(), setPixmap(), accel(), setAccel(), isToggleButton(), setDown(), isDown(), isOn(), checkState(), autoRepeat(), isExclusiveToggle(), group(), setAutoRepeat(), toggle(), pressed(), released(), clicked(), toggled(), checkState(), and stateChanged().

Screenshot of a Macintosh style checkboxA checkbox shown in the Macintosh widget style.
Screenshot of a Windows XP style checkboxA checkbox shown in the Windows XP widget style.
Screenshot of a Plastique style checkboxA checkbox shown in the Plastique widget style.

See also QAbstractButton, QRadioButton, and GUI Design Handbook: Check Box.

Property Documentation

tristate : bool

This property holds whether the checkbox is a tri-state checkbox.

The default is false; i.e. the checkbox has only two states.

Access functions:

bool isTristate () const
void setTristate ( bool y = true )

Member Function Documentation

QCheckBox::QCheckBox ( QWidget * parent = 0 )

Constructs a checkbox with the given parent, but with no text.

parent is passed on to the QAbstractButton constructor.

QCheckBox::QCheckBox ( const QString & text, QWidget * parent = 0 )

Constructs a checkbox with the given parent and text.

parent is passed on to the QAbstractButton constructor.

Qt::CheckState QCheckBox::checkState () const

Returns the check box's check state. If you do not need tristate support, you can also use QAbstractButton::isChecked() which returns a boolean.

See also setCheckState() and Qt::CheckState.

void QCheckBox::checkStateSet () [virtual protected]

Reimplemented from QAbstractButton::checkStateSet().

bool QCheckBox::event ( QEvent * e ) [virtual protected]

Reimplemented from QObject::event().

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

Reimplemented from QAbstractButton::hitButton().

void QCheckBox::initStyleOption ( QStyleOptionButton * option ) const [protected]

Initializes option with the values from this QCheckBox. This method is useful for subclasses that require a QStyleOptionButton, but do not want to fill in all the information themselves.

See also QStyleOption::initFrom().

void QCheckBox::mouseMoveEvent ( QMouseEvent * e ) [virtual protected]

Reimplemented from QWidget::mouseMoveEvent().

void QCheckBox::nextCheckState () [virtual protected]

Reimplemented from QAbstractButton::nextCheckState().

void QCheckBox::paintEvent ( QPaintEvent * ) [virtual protected]

Reimplemented from QWidget::paintEvent().

void QCheckBox::setCheckState ( Qt::CheckState state )

Sets the check box's check state to state. If you do not need tristate support, you can also use QAbstractButton::setChecked() which takes a boolean.

See also checkState() and Qt::CheckState.

QSize QCheckBox::sizeHint () const [virtual]

Reimplemented from QWidget::sizeHint().

void QCheckBox::stateChanged ( int state ) [signal]

This signal is emitted whenever the check box's state changes, i.e. whenever the user checks or unchecks it.

state contains the check box's new Qt::CheckState.

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. 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
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  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 Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. 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.7-snapshot
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