QGroupBox Class

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

头文件: #include <QGroupBox>
qmake: QT += widgets
基类: QWidget

属性

公有函数

QGroupBox(QWidget *parent = Q_NULLPTR)
QGroupBox(const QString &title, QWidget *parent = Q_NULLPTR)
~QGroupBox()
Qt::Alignment alignment() const
bool isCheckable() const
bool isChecked() const
bool isFlat() const
void setAlignment(int alignment)
void setCheckable(bool checkable)
void setFlat(bool flat)
void setTitle(const QString &title)
QString title() const

重新实现的公有函数

virtual QSize minimumSizeHint() const

公有槽函数

void setChecked(bool checked)
  • 19 个公有槽函数继承自 QWidget
  • 1 个公有槽函数继承自 QObject

信号

void clicked(bool checked = false)
void toggled(bool on)

受保护的函数

void initStyleOption(QStyleOptionGroupBox *option) const

重新实现的受保护函数

virtual void changeEvent(QEvent *ev)
virtual void childEvent(QChildEvent *c)
virtual bool event(QEvent *e)
virtual void focusInEvent(QFocusEvent *fe)
virtual void mouseMoveEvent(QMouseEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void paintEvent(QPaintEvent *event)
virtual void resizeEvent(QResizeEvent *e)
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject
  • 1 个受保护的槽函数继承自 QWidget
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

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

A group box provides a frame, a title on top, a keyboard shortcut, and displays various other widgets inside itself. 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:


      QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));

      QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
      QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
      QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));

      radio1->setChecked(true);

      QVBoxLayout *vbox = new QVBoxLayout;
      vbox->addWidget(radio1);
      vbox->addWidget(radio2);
      vbox->addWidget(radio3);
      vbox->addStretch(1);
      groupBox->setLayout(vbox);

Screenshot of a Windows Vista style group boxScreenshot of a Macintosh style group boxScreenshot of a Fusion style group box
A Windows Vista style group box.A Macintosh style group box.A Fusion style group box.

参见 QButtonGroup and Group Box Example.

属性

alignment : 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.

访问函数:

Qt::Alignment alignment() const
void setAlignment(int alignment)

参见 Qt::Alignment.

checkable : 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.

访问函数:

bool isCheckable() const
void setCheckable(bool checkable)

参见 checked.

checked : 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.

访问函数:

bool isChecked() const
void setChecked(bool checked)

Notifier signal:

void toggled(bool on)

参见 checkable.

flat : 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.

访问函数:

bool isFlat() const
void setFlat(bool flat)

参见 title.

title : 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.


  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.

访问函数:

QString title() const
void setTitle(const QString &title)

参见 alignment.

成员函数

QGroupBox::QGroupBox(QWidget *parent = Q_NULLPTR)

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

QGroupBox::QGroupBox(const QString &title, QWidget *parent = Q_NULLPTR)

Constructs a group box with the given title and parent.

QGroupBox::~QGroupBox()

Destroys the group box.

[virtual protected] void QGroupBox::changeEvent(QEvent *ev)

重新实现 QWidget::changeEvent().

[virtual protected] void QGroupBox::childEvent(QChildEvent *c)

重新实现 QObject::childEvent().

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

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.

This function was introduced in Qt 4.2.

参见 checkable, toggled(), and checked.

[virtual protected] bool QGroupBox::event(QEvent *e)

重新实现 QObject::event().

[virtual protected] void QGroupBox::focusInEvent(QFocusEvent *fe)

重新实现 QWidget::focusInEvent().

[protected] void QGroupBox::initStyleOption(QStyleOptionGroupBox *option) const

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.

参见 QStyleOption::initFrom().

[virtual] QSize QGroupBox::minimumSizeHint() const

重新实现 QWidget::minimumSizeHint().

[virtual protected] void QGroupBox::mouseMoveEvent(QMouseEvent *event)

重新实现 QWidget::mouseMoveEvent().

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

重新实现 QWidget::mousePressEvent().

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

重新实现 QWidget::mouseReleaseEvent().

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

重新实现 QWidget::paintEvent().

[virtual protected] void QGroupBox::resizeEvent(QResizeEvent *e)

重新实现 QWidget::resizeEvent().

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

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.

Note: Notifier signal for property checked.

参见 checkable.