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  · 

QCheckBox Class

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

 #include <QCheckBox>

Inherits: QAbstractButton.

Public Types

enum PaintDeviceMetric { PdmWidth, PdmHeight, PdmWidthMM, PdmHeightMM, ..., PdmPhysicalDpiY }

Properties

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

Public Functions

QAbstractButton(QWidget * parent = 0)
QCheckBox(QWidget * parent = 0)
QCheckBox(const QString & text, QWidget * parent = 0)
~QAbstractButton()
virtual ~QPaintDevice()
bool autoExclusive() const
bool autoRepeat() const
int autoRepeatDelay() const
int autoRepeatInterval() const
Qt::CheckState checkState() const
int colorCount() const
int depth() const
QButtonGroup * group() const
int height() const
int heightMM() const
QIcon icon() const
QSize iconSize() const
bool isCheckable() const
bool isChecked() const
bool isDown() const
bool isTristate() const
int logicalDpiX() const
int logicalDpiY() const
virtual QPaintEngine * paintEngine() const = 0
bool paintingActive() const
int physicalDpiX() const
int physicalDpiY() const
void setAutoExclusive(bool)
void setAutoRepeat(bool)
void setAutoRepeatDelay(int)
void setAutoRepeatInterval(int)
void setCheckState(Qt::CheckState state)
void setCheckable(bool)
void setDown(bool)
void setIcon(const QIcon & icon)
void setShortcut(const QKeySequence & key)
void setText(const QString & text)
void setTristate(bool y = true)
QKeySequence shortcut() const
QString text() const
int width() const
int widthMM() const

Reimplemented Public Functions

virtual QSize minimumSizeHint() const
virtual QSize sizeHint() const
  • 215 public functions inherited from QWidget
  • 31 public functions inherited from QObject

Public Slots

void animateClick(int msec = 100)
void click()
void setChecked(bool)
void setIconSize(const QSize & size)
void toggle()
  • 19 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

void clicked(bool checked = false)
void pressed()
void released()
void stateChanged(int state)
void toggled(bool checked)

Protected Functions

QPaintDevice()
virtual void changeEvent(QEvent * e)
virtual void checkStateSet()
virtual bool event(QEvent * e)
virtual void focusInEvent(QFocusEvent * e)
virtual void focusOutEvent(QFocusEvent * e)
virtual bool hitButton(const QPoint & pos) const
virtual void init(QPainter * painter) const
void initStyleOption(QStyleOptionButton * option) const
virtual void keyPressEvent(QKeyEvent * e)
virtual void keyReleaseEvent(QKeyEvent * e)
virtual int metric(PaintDeviceMetric metric) const
virtual void mouseMoveEvent(QMouseEvent * e)
virtual void mousePressEvent(QMouseEvent * e)
virtual void mouseReleaseEvent(QMouseEvent * e)
virtual void nextCheckState()
virtual void paintEvent(QPaintEvent * e) = 0
virtual QPaintDevice * redirected(QPoint * offset) const
virtual QPainter * sharedPainter() const
virtual void timerEvent(QTimerEvent * e)

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 *)
  • 37 protected functions inherited from QWidget
  • 9 protected functions inherited from QObject

Additional Inherited Members

  • 4 static public members inherited from QWidget
  • 11 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().

QSize QCheckBox::minimumSizeHint() const [virtual]

Reimplemented from QWidget::minimumSizeHint().

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.

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 5.0-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