6.0.0-rc4Source

QAbstractButton Class

The QAbstractButton class is the abstract base class of button widgets. More…

Header#include <QAbstractButton>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget
Inherited byQCheckBox, QPushButton, QRadioButton, QToolButton

List of all members, including inherited members

Public Functions

~QAbstractButton()
QStringtext() const
voidsetText(const QString &text)
boolisCheckable() const
voidsetCheckable(bool checkable)
boolisChecked() const
boolisDown() const
voidsetDown(bool down)
boolautoExclusive() const
voidsetAutoExclusive(bool exclusive)
QButtonGroup *group() const

Public Slots

voidsetChecked(bool checked)
voidclick()
voidtoggle()

Signals

voidpressed()
voidreleased()
voidclicked(bool checked = false)
voidtoggled(bool checked)

Protected Functions

QAbstractButton(QWidget *parent = nullptr)
virtual boolhitButton(const QPoint &pos) const

Reimplemented Protected Functions

Detailed Description

A button has a text and can be pressed. It is clicked when the mouse button is released inside it, or when Space is pressed and released while the button has the focus, or when click() is called. A checkable button toggles on each click.

QPushButton *button = new QPushButton("Subscribe");
button->setCheckable(true);
connect(button, &QPushButton::toggled, [](bool on) { qDebug() << on; });

See also QPushButton and QCheckBox.

Differences from Qt

There are no icons, shortcuts (setShortcut()), auto-repeat, animateClick(), setIcon() or setIconSize().

Member Function Documentation

[explicit, protected] QAbstractButton::QAbstractButton(QWidget *parent = nullptr)

Constructs a button with the given parent.

[override] QAbstractButton::~QAbstractButton()

Destroys the button.

bool QAbstractButton::autoExclusive() const

Returns whether the button is auto-exclusive: of all the auto-exclusive buttons that have the same parent widget, only one is checked at a time, and checking one unchecks the others. A checked button of such a group cannot be unchecked, only another one can be checked. A button in a QButtonGroup follows the group instead. The default is false, and radio buttons set it.

See also setAutoExclusive().

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

Reimplements QWidget::changeEvent().

[slot] void QAbstractButton::click()

Clicks the button as if the user did: it is pressed and released, so pressed(), released() and clicked() are emitted, and a checkable button toggles. Nothing happens if the button is disabled.

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

This signal is emitted when the button is activated: pressed and released with the mouse, or triggered with the keyboard or click(). checked is the checked state of a checkable button.

[override, protected] void QAbstractButton::enterEvent(QEnterEvent *event)

Reimplements QWidget::enterEvent().

[override, protected] void QAbstractButton::focusOutEvent(QFocusEvent *event)

Reimplements QWidget::focusOutEvent().

QButtonGroup * QAbstractButton::group() const

Returns the group that the button belongs to, or nullptr if it is in none.

See also QButtonGroup::addButton().

[virtual, protected] bool QAbstractButton::hitButton(const QPoint &pos) const

Returns true if pos, in the coordinates of the button, is on the part that reacts to the mouse. The default is the whole rectangle.

bool QAbstractButton::isCheckable() const

Returns whether the button is checkable: it toggles when it is clicked. The default is false.

See also setCheckable().

bool QAbstractButton::isChecked() const

Returns whether a checkable button is checked.

See also setChecked().

bool QAbstractButton::isDown() const

Returns whether the button is pressed down.

See also setDown().

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

Reimplements QWidget::keyPressEvent().

[override, protected] void QAbstractButton::keyReleaseEvent(QKeyEvent *event)

Reimplements QWidget::keyReleaseEvent().

[override, protected] void QAbstractButton::leaveEvent(QEvent *event)

Reimplements QWidget::leaveEvent().

[override, protected] void QAbstractButton::mouseMoveEvent(QMouseEvent *event)

Reimplements QWidget::mouseMoveEvent().

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

Reimplements QWidget::mousePressEvent().

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

Reimplements QWidget::mouseReleaseEvent().

[signal] void QAbstractButton::pressed()

This signal is emitted when the button is pressed down.

[signal] void QAbstractButton::released()

This signal is emitted when the button is released.

void QAbstractButton::setAutoExclusive(bool exclusive)

Sets whether the button is auto-exclusive to exclusive.

See also autoExclusive().

void QAbstractButton::setCheckable(bool checkable)

Sets whether the button is checkable to checkable.

See also isCheckable().

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

Checks a checkable button if checked is true, and unchecks it otherwise. Emits toggled() if the state changes. Nothing happens if the button is not checkable.

See also isChecked().

void QAbstractButton::setDown(bool down)

Sets whether the button looks pressed down to down. Mouse and key events do this by themselves.

See also isDown().

void QAbstractButton::setText(const QString &text)

Sets the text of the button to text.

See also text().

QString QAbstractButton::text() const

Returns the text of the button.

See also setText().

[slot] void QAbstractButton::toggle()

Toggles a checkable button.

See also setChecked().

[signal] void QAbstractButton::toggled(bool checked)

This signal is emitted when the checked state of a checkable button changes to checked.