Qtopia Home - Classes - Hierachy - Annotated - Functions - Licenses - Reference

QCheckBox Class Reference

The QCheckBox widget provides a check box with a text label. More...

#include <qcheckbox.h>

Inherits QButton.

List of all member functions.

Public Members

Important Inherited Members

Properties


Detailed Description

The QCheckBox widget provides a check box with a text label.

QCheckBox and QRadioButton are both option buttons. That is, they can be switched on (checked) or off (unchecked). The classes differ in how the choices for the user are restricted. Radio buttons define a "one of many" choice, while check-boxes provide "many of many" choices.

While it is technically possible to implement radio-behaviour with check boxes and vice versa, it's strongly recommended to stick with the well-known semantics. Otherwise your users would be pretty confused.

Use QButtonGroup to group check-buttons visually.

Whenver a check box is checked or cleared, it emits the signal toggled(). Connect to this signal if you want to trigger an action each time the box changes state. Otherwise, use isChecked() to query whether or not a particular check box is selected.

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 setting nor unsetting an option. If you need that third state, enable it with setTristate() and use state() to query the current toggle state. When a tristate box changes state, it emits the stateChanged() signal.

See also QButton, QRadioButton, and Fowler: Check Box..


Member Function Documentation

QCheckBox::QCheckBox ( QWidget * parent, const char * name = 0 )

Constructs a check box with no text.

The parent and name arguments are sent to the QWidget constructor.

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

Constructs a check box with a text.

The parent and name arguments are sent to the QWidget constructor.

int QButton::accel () const

Returns the accelerator key currently set for the button, or 0 if no accelerator key has been set.

See also setAccel().

bool QButton::autoRepeat () const

Returns TRUE if the button is auto-repeating, else FALSE.

The default is FALSE.

See also setAutoRepeat().

QButtonGroup * QButton::group () const

Returns a pointer to the group of which this button is a member.

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

See also setGroup() and QButtonGroup.

bool QCheckBox::isChecked () const

Returns TRUE if the check box is checked, or FALSE if it is not checked.

See also setChecked().

bool QButton::isDown () const

Returns TRUE if the button pressed down, or FALSE if it is standing up.

See also setDown().

bool QButton::isExclusiveToggle () const

Returns TRUE if this button behaves exclusively inside a QButtonGroup. In that case, this button can only be toggled off by another button being toggled on.

bool QButton::isOn () const

Returns TRUE if this toggle button is switched on, or FALSE if it is switched off.

See also setOn() and isToggleButton().

bool QButton::isToggleButton () const

Returns TRUE if the button is a toggle button.

See also setToggleButton().

bool QCheckBox::isTristate () const

Returns TRUE if the checkbox is a tristate checkbox. Otherwise returns FALSE.

See also setTristate().

const QPixmap * QButton::pixmap () const

Returns the button pixmap, or 0 if the button has no pixmap.

void QButton::pressed () [signal]

This signal is emitted when the button is pressed down.

See also released() and clicked().

void QButton::released () [signal]

This signal is emitted when the button is released.

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

void QButton::setAccel ( int key ) [virtual]

Specifies an accelerator key for the button, or removes the accelerator if key is 0.

Setting a button text containing a shortcut character (for example the 'x' in E&xit) automatically defines an ALT+letter accelerator for the button. You only need to call this function in order to specify a custom accelerator.

Example:

    QPushButton *b1 = new QPushButton;
    b1->setText( "&OK" );               // sets accel ALT+'O'

    QPushButton *b2 = new QPushButton;
    b2->setPixmap( printIcon );         // pixmap instead of text
    b2->setAccel( CTRL+'P' );           // custom accel
  

See also accel(), setText(), and QAccel.

void QButton::setAutoRepeat ( bool enable ) [virtual]

Turns on auto-repeat for the button if enable is TRUE, or turns it off if enable is FALSE.

When auto-repeat is enabled, the clicked() signal is emitted at regular intervals while the buttons is down.

setAutoRepeat() has no effect for toggle buttons.

See also isDown(), autoRepeat(), and clicked().

void QCheckBox::setChecked ( bool check )

Checks the check box if check is TRUE, or unchecks it if check is FALSE.

See also isChecked().

void QButton::setDown ( bool enable ) [virtual]

Sets the state of the button to pressed down if enable is TRUE or to standing up if enable is FALSE.

If the button is a toggle button, it is not toggled. Call toggle() as well if you need to do that. The pressed() and released() signals are not emitted by this function.

This method is provided in case you need to reimplement the mouse event handlers.

See also isDown(), setOn(), toggle(), and toggled().

void QCheckBox::setNoChange ()

Sets the checkbox into the "no change" state.

See also setTristate().

void QButton::setPixmap ( const QPixmap & pixmap ) [virtual]

Sets the button to display pixmap

If pixmap is monochrome (i.e. it is a QBitmap or its depth is 1) and it does not have a mask, this function sets the pixmap to be its own mask. The purpose of this is to draw transparent bitmaps, which is important for e.g. toggle buttons.

See also pixmap(), setText(), setAccel(), and QPixmap::mask().

void QButton::setText ( const QString & text ) [virtual]

Sets the button to display text.

If the text contains an ampersand, QButton creates an automatic accelerator for it, such as Alt-c for "&Cancel".

See also text(), setPixmap(), setAccel(), and QPixmap::mask().

void QCheckBox::setTristate ( bool y = TRUE )

Makes the check box a tristate check box if y is TRUE. A tristate check box provides an additional state NoChange.

Use tristate check boxes whenever you need to give the user the option of neither setting nor unsetting an option. A typical example is the "Italic" check box in the font dialog of a word processor when the marked text is partially Italic and partially not.

See also isTristate(), setNoChange(), stateChanged(), and state().

ToggleState QButton::state () const

Returns the state of the button.

See also ToggleState, ToggleType, and setState().

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

This signal is emitted whenever a toggle button changes status. state is 2 if the button is on, 1 if it is in the "no change" state or 0 if the button is off.

This may be the result of a user action, toggle() slot activation, setState(), or because setOn() was called.

See also clicked().

QString QButton::text () const

Returns the button text, or null string if the button has no text.

See also setText().

void QButton::toggle () [slot]

if this is a toggle button, toggles it.

void QButton::toggled ( bool on ) [signal]

This signal is emitted whenever a toggle button changes status. on is TRUE if the button is on, or FALSE if the button is off.

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

See also clicked().


This file is part of the Qtopia platform, copyright © 1995-2005 Trolltech, all rights reserved.


Copyright © 2005 Trolltech Trademarks
Qtopia version 2.2.0