QGroupBox Class Reference

The QGroupBox widget provides a group box frame with a title.

  1. #include <QGroupBox>

Inherits: QWidget.

Inherited by: Q3GroupBox.

Detailed Description

The QGroupBox widget provides a group box frame with a title.

A group box provides a frame, a title and a keyboard shortcut, and displays various other widgets inside itself. The title is on top, the keyboard shortcut moves keyboard focus to one of the group box's child widgets.

QGroupBox also lets you set the title (normally set in the constructor) and the title's alignment. Group boxes can be checkable; child widgets in checkable group boxes are enabled or disabled depending on whether or not the group box is checked.

You can minimize the space consumption of a group box by enabling the flat property. In most styles, enabling this property results in the removal of the left, right and bottom edges of the frame.

QGroupBox doesn't automatically lay out the child widgets (which are often QCheckBoxes or QRadioButtons but can be any widgets). The following example shows how we can set up a QGroupBox with a layout:

  1.     QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));
  2.  
  3.     QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
  4.     QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
  5.     QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));
  6.  
  7.     radio1->setChecked(true);
  8.  
  9.     QVBoxLayout *vbox = new QVBoxLayout;
  10.     vbox->addWidget(radio1);
  11.     vbox->addWidget(radio2);
  12.     vbox->addWidget(radio3);
  13.     vbox->addStretch(1);
  14.     groupBox->setLayout(vbox);
Screenshot of a Windows XP style group box

Screenshot of a Windows XP style group box

Screenshot of a Macintosh style group box

Screenshot of a Macintosh style group box

Screenshot of a Plastique style group box

Screenshot of a Plastique style group box

A Windows XP style group box.A Macintosh style group box.A Plastique style group box.

See also QButtonGroup and Group Box Example.

Properties

Toggle detailsalignmentalignment : Qt::Alignment

This property holds the alignment of the group box title.

Most styles place the title at the top of the frame. The horizontal alignment of the title can be specified using single values from the following list:

  • Qt::AlignLeft aligns the title text with the left-hand side of the group box.
  • Qt::AlignRight aligns the title text with the right-hand side of the group box.
  • Qt::AlignHCenter aligns the title text with the horizontal center of the group box.

The default alignment is Qt::AlignLeft.

See also Qt::Alignment.

Access functions:

Look up this member in the source code.

Toggle detailscheckablecheckable : bool

This property holds whether the group box has a checkbox in its title

If this property is true, the group box displays its title using a checkbox in place of an ordinary label. If the checkbox is checked, the group box's children are enabled; otherwise they are disabled and inaccessible.

By default, group boxes are not checkable.

If this property is enabled for a group box, it will also be initially checked to ensure that its contents are enabled.

See also checked.

Access functions:

Look up this member in the source code.

Toggle detailscheckedchecked : bool

This property holds whether the group box is checked

If the group box is checkable, it is displayed with a check box. If the check box is checked, the group box's children are enabled; otherwise the children are disabled and are inaccessible to the user.

By default, checkable group boxes are also checked.

See also checkable.

Access functions:

Look up this member in the source code.

Toggle detailsflatflat : bool

This property holds whether the group box is painted flat or has a frame

A group box usually consists of a surrounding frame with a title at the top. If this property is enabled, only the top part of the frame is drawn in most styles; otherwise the whole frame is drawn.

By default, this property is disabled; i.e. group boxes are not flat unless explicitly specified.

Note: In some styles, flat and non-flat group boxes have similar representations and may not be as distinguishable as they are in other styles.

See also title.

Access functions:

Look up this member in the source code.

Toggle detailstitletitle : QString

This property holds the group box title text

The group box title text will have a keyboard shortcut if the title contains an ampersand ('&') followed by a letter.

  1. g->setTitle("&User information");

In the example above, Alt+U moves the keyboard focus to the group box. See the QShortcut documentation for details (to display an actual ampersand, use '&&').

There is no default title text.

See also alignment.

Access functions:

Look up this member in the source code.

    Public Functions

    Toggle details QGroupBox

    QGroupBoxQGroupBox ( QWidget *parent=0 ) ( QWidget *parent=0 )

    Constructs a group box widget with the given parent but with no title.

    Look up this member in the source code.

    Toggle details QGroupBox

    QGroupBoxQGroupBox ( const QString &title , QWidget *parent=0 ...) ( const QString &title , QWidget *parent=0 )

    Constructs a group box with the given title and parent.

    Look up this member in the source code.

    Toggle details QGroupBox

    ~QGroupBox~QGroupBox () ()

    Destroys the group box.

    Look up this member in the source code.

    Toggle details void QGroupBox

    changeEventchangeEvent ( QEvent *ev ) ( QEvent *ev ) [virtual protected]

    Reimplemented from QWidget::changeEvent().

    Look up this member in the source code.

    Toggle details void QGroupBox

    childEventchildEvent ( QChildEvent *c ) ( QChildEvent *c ) [virtual protected]

    Reimplemented from QObject::childEvent().

    Look up this member in the source code.

    Toggle details bool QGroupBox

    eventevent ( QEvent *e ) ( QEvent *e ) [virtual protected]

    Reimplemented from QObject::event().

    Look up this member in the source code.

    Toggle details void QGroupBox

    focusInEventfocusInEvent ( QFocusEvent *fe ) ( QFocusEvent *fe ) [virtual protected]

    Reimplemented from QWidget::focusInEvent().

    Look up this member in the source code.

    Toggle details void QGroupBox

    initStyleOptioninitStyleOption ( QStyleOptionGroupBox *option ( QStyleOptionGroupBox *option )const[protected]

    Initialize option with the values from this QGroupBox. This method is useful for subclasses when they need a QStyleOptionGroupBox, but don't want to fill in all the information themselves.

    See also QStyleOption::initFrom().

    Look up this member in the source code.

    Toggle details QSize QGroupBox

    minimumSizeHintminimumSizeHint () ()const [virtual]

    Reimplemented from QWidget::minimumSizeHint().

    Look up this member in the source code.

    Toggle details void QGroupBox

    mouseMoveEventmouseMoveEvent ( QMouseEvent *event ) ( QMouseEvent *event ) [virtual protected]

    Reimplemented from QWidget::mouseMoveEvent().

    Look up this member in the source code.

    Toggle details void QGroupBox

    mousePressEventmousePressEvent ( QMouseEvent *event ) ( QMouseEvent *event ) [virtual protected]

    Reimplemented from QWidget::mousePressEvent().

    Look up this member in the source code.

    Toggle details void QGroupBox

    mouseReleaseEventmouseReleaseEvent ( QMouseEvent *event ) ( QMouseEvent *event ) [virtual protected]

    Reimplemented from QWidget::mouseReleaseEvent().

    Look up this member in the source code.

    Toggle details void QGroupBox

    paintEventpaintEvent ( QPaintEvent *event ) ( QPaintEvent *event ) [virtual protected]

    Reimplemented from QWidget::paintEvent().

    Look up this member in the source code.

    Toggle details void QGroupBox

    resizeEventresizeEvent ( QResizeEvent *e ) ( QResizeEvent *e ) [virtual protected]

    Reimplemented from QWidget::resizeEvent().

    Look up this member in the source code.

    Toggle details QGroupBox

    QGroupBoxQGroupBox ( QWidget *parent , const char *name ) ( QWidget *parent , const char *name ) Qt3-support

    Use one of the constructors that doesn't take the name argument and then use setObjectName() instead.

    Look up this member in the source code.

    Toggle details QGroupBox

    QGroupBoxQGroupBox ( const QString &title , QWidget *parent , const char *name ...) ( const QString &title , QWidget *parent , const char *name ) Qt3-support

    Use one of the constructors that doesn't take the name argument and then use setObjectName() instead.

    Look up this member in the source code.

    Signals

    Toggle details void QGroupBox

    clickedclicked ( bool checked=false ) ( bool checked=false ) [signal]

    This signal is emitted when the check box is activated (i.e. pressed down then released while the mouse cursor is inside the button), or when the shortcut key is typed, Notably, this signal is not emitted if you call setChecked().

    If the check box is checked checked is true; it is false if the check box is unchecked.

    See also checkable, toggled(), and checked.

    Look up this member in the source code.

    Toggle details void QGroupBox

    toggledtoggled ( bool on ) ( bool on ) [signal]

    If the group box is checkable, this signal is emitted when the check box is toggled. on is true if the check box is checked; otherwise it is false.

    See also checkable.

    Look up this member in the source code.

    Notes provided by the Qt Community

    No notes