6.0.0-rc4Source

QGroupBox Class

The QGroupBox class is a frame with a title that groups other widgets. More…

Header#include <QGroupBox>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget

List of all members, including inherited members

Public Functions

QGroupBox(QWidget *parent = nullptr)
QGroupBox(const QString &title, QWidget *parent = nullptr)
~QGroupBox()
QStringtitle() const
voidsetTitle(const QString &title)
boolisCheckable() const
voidsetCheckable(bool checkable)
boolisChecked() const

Reimplemented Public Functions

Public Slots

voidsetChecked(bool checked)

Signals

voidtoggled(bool on)
voidclicked(bool checked = false)

Reimplemented Protected Functions

Detailed Description

A group box draws a frame around its children, with a title on its top edge. Put a layout on it for the children, as for any widget. The radio buttons that are children of a group box are exclusive to each other, which is the way to have several groups of them in a window:

QGroupBox *box = new QGroupBox("Size", window);
QVBoxLayout *layout = new QVBoxLayout(box);
layout->addWidget(new QRadioButton("Small", box));
layout->addWidget(new QRadioButton("Large", box));

A checkable group box has a check box in its title, and its children are disabled while it is unchecked.

Group boxes: plain, checkable and checked, and checkable and unchecked, which disables what is inside.

QGroupBox in the light color scheme

See also QRadioButton and QCheckBox.

Differences from Qt

The title is always at the top left: there is no setAlignment(), and no setFlat(). The children are enabled and disabled when the group box is checked and unchecked, but not when they are added later.

Member Function Documentation

[explicit] QGroupBox::QGroupBox(QWidget *parent = nullptr)

Constructs a group box with no title and the given parent.

[explicit] QGroupBox::QGroupBox(const QString &title, QWidget *parent = nullptr)

Constructs a group box with the title title and the given parent.

[override] QGroupBox::~QGroupBox()

Destroys the group box.

[override, protected] void QGroupBox::changeEvent(QEvent *event)

Reimplements QWidget::changeEvent().

[signal] void QGroupBox::clicked(bool checked = false)

This signal is emitted when the user clicks the check box in the title of the group box, and checked is its state afterwards.

bool QGroupBox::isCheckable() const

Returns whether the group box has a check box in its title. The default is false.

See also setCheckable() and isChecked().

bool QGroupBox::isChecked() const

Returns whether a checkable group box is checked, which it is at first.

See also setChecked().

[override, protected] void QGroupBox::keyPressEvent(QKeyEvent *event)

Reimplements QWidget::keyPressEvent().

[override] QSize QGroupBox::minimumSizeHint() const

Reimplements QWidget::minimumSizeHint().

[override, protected] void QGroupBox::mousePressEvent(QMouseEvent *event)

Reimplements QWidget::mousePressEvent().

[override, protected] void QGroupBox::mouseReleaseEvent(QMouseEvent *event)

Reimplements QWidget::mouseReleaseEvent().

[override, protected] void QGroupBox::paintEvent(QPaintEvent *event)

Reimplements QWidget::paintEvent().

void QGroupBox::setCheckable(bool checkable)

Sets whether the group box has a check box in its title to checkable. A checkable group box can be given the keyboard focus.

See also isCheckable().

[slot] void QGroupBox::setChecked(bool checked)

Checks a checkable group box if checked is true and unchecks it otherwise, which enables or disables its children. Emits toggled() if the state changes.

See also isChecked().

void QGroupBox::setTitle(const QString &title)

Sets the title to title.

See also title().

[override] QSize QGroupBox::sizeHint() const

Reimplements QWidget::sizeHint().

QString QGroupBox::title() const

Returns the title.

See also setTitle().

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

This signal is emitted when the state of a checkable group box changes to on.