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

QRadioButton Class Reference

The QRadioButton widget provides a radio button with a text label. More...

#include <qradiobutton.h>

Inherits QButton.

List of all member functions.

Public Members

Important Inherited Members

Properties


Detailed Description

The QRadioButton widget provides a radio button with a text label.

QRadioButton and QCheckBox 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. Check-boxes define "many of many" choices, while radio buttons provide a "one of many" choice. In a group of radio buttons, only one button at a time can be checked. If the user selects another button, the previously selected button is switched off.

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.

The easiest way to implement a "one of many" choice, is to simply stick the radio buttons into QButtonGroup.

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

See also QPushButton, QToolButton, and GUI Design Handbook: Radio Button.


Member Function Documentation

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

Constructs a radio button with no text.

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

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

Constructs a radio button 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 QRadioButton::isChecked () const

Returns TRUE if the radio button 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().

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 QRadioButton::setChecked ( bool check ) [virtual]

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

Calling this function does not affect other radio buttons unless a radio button group has been defined using the QButtonGroup widget.

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 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().

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