QButtonGroup Class Reference

#include <qbuttongroup.h>

Inheritance diagram for QButtonGroup:

Inheritance graph
[legend]
Collaboration diagram for QButtonGroup:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QButtonGroup class provides a container to organize groups of button widgets.

QButtonGroup provides an abstract container into which button widgets can be placed. It does not provide a visual representation of this container (see QGroupBox for a container widget), but instead manages the states of each of the buttons in the group.

An exclusive button group switches off all checkable (toggle) buttons except the one that was clicked. By default, a button group is exclusive. The buttons in a button group are usually checkable QPushButton's, {QCheckBox}es (normally for non-exclusive button groups), or {QRadioButton}s. If you create an exclusive button group, you should ensure that one of the buttons in the group is initially checked; otherwise, the group will initially be in a state where no buttons are checked.

A button is added to the group with addButton(). It can be removed from the group with removeButton(). If the group is exclusive, the currently checked button is available as checkedButton(). If a button is clicked the buttonClicked() signal is emitted. For a checkable button in an exclusive group this means that the button was checked. The list of buttons in the group is returned by buttons().

In addition, QButtonGroup can map between integers and buttons. You can assign an integer id to a button with setId(), and retrieve it with id(). The id of the currently checked button is available with checkedId(), and there is an overloaded signal buttonClicked() which emits the id of the button. The purpose of the mapping mechanism is to simplify the representation of enum values in a user interface.

See also:
QGroupBox QPushButton, QCheckBox, QRadioButton

Definition at line 39 of file qbuttongroup.h.

Signals

void buttonClicked (QAbstractButton *)
void buttonClicked (int)
void buttonPressed (QAbstractButton *)
void buttonPressed (int)
void buttonReleased (QAbstractButton *)
void buttonReleased (int)

Public Member Functions

 QButtonGroup (QObject *parent=0)
 ~QButtonGroup ()
void setExclusive (bool)
bool exclusive () const
void addButton (QAbstractButton *)
void addButton (QAbstractButton *, int id)
void removeButton (QAbstractButton *)
QList< QAbstractButton * > buttons () const
QAbstractButtoncheckedButton () const
QAbstractButtonbutton (int id) const
void setId (QAbstractButton *button, int id)
int id (QAbstractButton *button) const
int checkedId () const

Friends

class QAbstractButton
class QAbstractButtonPrivate


Constructor & Destructor Documentation

QButtonGroup::QButtonGroup ( QObject parent = 0  )  [explicit]

Constructs a new, empty button group with the given parent.

See also:
addButton() setExclusive()

Definition at line 175 of file qabstractbutton.cpp.

00176     : QObject(*new QButtonGroupPrivate, parent)
00177 {
00178 }

QButtonGroup::~QButtonGroup (  ) 

Destroys the button group.

Definition at line 180 of file qabstractbutton.cpp.

References d, and i.

00181 {
00182     Q_D(QButtonGroup);
00183     for (int i = 0; i < d->buttonList.count(); ++i)
00184         d->buttonList.at(i)->d_func()->group = 0;
00185 }


Member Function Documentation

void QButtonGroup::setExclusive ( bool   ) 

Definition at line 194 of file qabstractbutton.cpp.

References d.

Referenced by Q3ButtonGroup::init(), and Q3ButtonGroup::setExclusive().

00195 {
00196     Q_D(QButtonGroup);
00197     d->exclusive = exclusive;
00198 }

bool QButtonGroup::exclusive (  )  const

Definition at line 188 of file qabstractbutton.cpp.

References d.

Referenced by QAbstractButtonPrivate::click(), Q3ButtonGroup::event(), Q3ButtonGroup::isExclusive(), QAbstractButtonPrivate::moveFocus(), and QAbstractButtonPrivate::notifyChecked().

00189 {
00190     Q_D(const QButtonGroup);
00191     return d->exclusive;
00192 }

void QButtonGroup::addButton ( QAbstractButton button  ) 

Adds the given button to the end of the group's internal list of buttons.

See also:
removeButton()

Definition at line 205 of file qabstractbutton.cpp.

References button().

Referenced by Q3ButtonGroup::insert_helper().

00206 {
00207     addButton(button, -1);
00208 }

Here is the call graph for this function:

void QButtonGroup::addButton ( QAbstractButton button,
int  id = -1 
)

Adds the given button to the button group, with the given id.

See also:
removeButton() buttons()

Definition at line 210 of file qabstractbutton.cpp.

References button(), d, QAbstractButton::group(), and QAbstractButton::isChecked().

00211 {
00212     Q_D(QButtonGroup);
00213     if (QButtonGroup *previous = button->d_func()->group)
00214         previous->removeButton(button);
00215     button->d_func()->group = this;
00216     d->buttonList.append(button);
00217     if (id != -1)
00218         d->mapping[button] = id;
00219     if (d->exclusive && button->isChecked())
00220         button->d_func()->notifyChecked();
00221 }

Here is the call graph for this function:

void QButtonGroup::removeButton ( QAbstractButton button  ) 

Removes the given button from the button group.

See also:
addButton() buttons()

Definition at line 223 of file qabstractbutton.cpp.

References button(), d, and QAbstractButton::group().

Referenced by Q3ButtonGroup::remove().

00224 {
00225     Q_D(QButtonGroup);
00226     if (d->checkedButton == button) {
00227         d->detectCheckedButton();
00228     }
00229     if (button->d_func()->group == this) {
00230         button->d_func()->group = 0;
00231         d->buttonList.removeAll(button);
00232         d->mapping.remove(button);
00233     }
00234 }

Here is the call graph for this function:

QList< QAbstractButton * > QButtonGroup::buttons (  )  const

Returns the list of this groups's buttons. This may be empty.

See also:
addButton(), removeButton()

Definition at line 236 of file qabstractbutton.cpp.

References d.

00237 {
00238     Q_D(const QButtonGroup);
00239     return d->buttonList;
00240 }

QAbstractButton * QButtonGroup::checkedButton (  )  const

Returns the button group's checked button, or 0 if no buttons are checked.

See also:
buttonClicked()

Definition at line 242 of file qabstractbutton.cpp.

References d.

Referenced by QAbstractButtonPrivate::notifyChecked(), and QAbstractButtonPrivate::queryCheckedButton().

00243 {
00244     Q_D(const QButtonGroup);
00245     return d->checkedButton;
00246 }

QAbstractButton * QButtonGroup::button ( int  id  )  const

Since:
4.1
Returns the button with the specified id, or 0 if no such button exists.

Definition at line 248 of file qabstractbutton.cpp.

References d.

Referenced by addButton(), id(), removeButton(), and setId().

00249 {
00250     Q_D(const QButtonGroup);
00251     return d->mapping.key(id);
00252 }

void QButtonGroup::setId ( QAbstractButton button,
int  id 
)

Since:
4.1
Sets the id for the specified button.

See also:
id()

Definition at line 254 of file qabstractbutton.cpp.

References button(), and d.

00255 {
00256     Q_D(QButtonGroup);
00257     if (button && id != -1)
00258         d->mapping[button] = id;
00259 }

Here is the call graph for this function:

int QButtonGroup::id ( QAbstractButton button  )  const

Since:
4.1
Returns the id for the specified button, or -1 if no such button exists.

See also:
setId()

Definition at line 261 of file qabstractbutton.cpp.

References button(), and d.

Referenced by QAbstractButtonPrivate::emitClicked(), QAbstractButtonPrivate::emitPressed(), and QAbstractButtonPrivate::emitReleased().

00262 {
00263     Q_D(const QButtonGroup);
00264     return d->mapping.value(button, -1);
00265 }

Here is the call graph for this function:

int QButtonGroup::checkedId (  )  const

Since:
4.1
Returns the id of the checkedButton(), or -1 if no button is checked.

See also:
setId()

Definition at line 267 of file qabstractbutton.cpp.

References d.

00268 {
00269     Q_D(const QButtonGroup);
00270     return d->mapping.value(d->checkedButton, -1);
00271 }

void QButtonGroup::buttonClicked ( QAbstractButton button  )  [signal]

This signal is emitted when the given button is clicked. A button is clicked when it is first pressed and then released, when its shortcut key is typed, or programmatically when QAbstractButton::click() or QAbstractButton::animateClick() is called.

See also:
checkedButton(), QAbstractButton::clicked()

Referenced by QAbstractButtonPrivate::emitClicked().

void QButtonGroup::buttonClicked ( int  id  )  [signal]

This signal is emitted when a button with the given id is clicked.

See also:
checkedButton(), QAbstractButton::clicked()

void QButtonGroup::buttonPressed ( QAbstractButton button  )  [signal]

Since:
4.2
This signal is emitted when the given button is pressed down.

See also:
QAbstractButton::pressed()

Referenced by QAbstractButtonPrivate::emitPressed().

void QButtonGroup::buttonPressed ( int  id  )  [signal]

Since:
4.2
This signal is emitted when a button with the given id is pressed down.

See also:
QAbstractButton::pressed()

void QButtonGroup::buttonReleased ( QAbstractButton button  )  [signal]

Since:
4.2
This signal is emitted when the given button is released.

See also:
QAbstractButton::released()

Referenced by QAbstractButtonPrivate::emitReleased().

void QButtonGroup::buttonReleased ( int  id  )  [signal]

Since:
4.2
This signal is emitted when a button with the given id is released.

See also:
QAbstractButton::released()


Friends And Related Function Documentation

friend class QAbstractButton [friend]

Definition at line 82 of file qbuttongroup.h.

friend class QAbstractButtonPrivate [friend]

Definition at line 83 of file qbuttongroup.h.


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:54:01 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1