QButton(3qt)
π NAME π
QButton β the abstract base class of button widgets, providing functionality common to buttons.
yep, that's this whole page (QButton(3qt), if you're being formal about it π). it's giving "mom of the button family" energy and honestly? iconic.
π¦ SYNOPSIS π¦
#include <qbutton.h>
Inherits QWidget.
Inherited by QCheckBox, QPushButton, QRadioButton, and QToolButton.
β¨ Public Members β¨
QButton ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )~QButton ()QString text () constvirtual void setText ( const QString & )const QPixmap * pixmap () constvirtual void setPixmap ( const QPixmap & )QKeySequence accel () constvirtual void setAccel ( const QKeySequence & )bool isToggleButton () constenum ToggleType { SingleShot, Toggle, Tristate }ToggleType toggleType () constvirtual void setDown ( bool )bool isDown () constbool isOn () constenum ToggleState { Off, NoChange, On }ToggleState state () constbool autoResize () const(obsolete)void setAutoResize ( bool )(obsolete)bool autoRepeat () constvirtual void setAutoRepeat ( bool )bool isExclusiveToggle () constQButtonGroup * group () const
π«Ά Public Slots π«Ά
void animateClick ()void toggle ()
π₯ Signals π₯
void pressed ()void released ()void clicked ()void toggled ( bool on )void stateChanged ( int state )
π Properties π
QKeySequence accelβ the accelerator associated with the buttonbool autoRepeatβ whether autoRepeat is enabledbool autoResizeβ whether autoResize is enabled (obsolete)bool downβ whether the button is pressedbool exclusiveToggleβ whether the button is an exclusive toggle (read only)bool onβ whether the button is toggled (read only)QPixmap pixmapβ the pixmap shown on the buttonQString textβ the text shown on the buttonbool toggleButtonβ whether the button is a toggle button (read only)ToggleState toggleStateβ the state of the toggle button (read only)ToggleType toggleTypeβ the type of toggle on the button (read only)
π§ Protected Members π§
void setToggleButton ( bool b )virtual void setToggleType ( ToggleType type )void setOn ( bool on )virtual void setState ( ToggleState s )virtual bool hitButton ( const QPoint & pos ) constvirtual void drawButton ( QPainter * )virtual void drawButtonLabel ( QPainter * )virtual void paintEvent ( QPaintEvent * )
πΈ DESCRIPTION πΈ
okay so. The QButton class is the abstract base class of button widgets, providing functionality common to buttons. bestie it's the blueprint, not the build π
If you actually want to create a button, use QPushButton.
QButton implements an abstract button, and lets subclasses decide how to reply to user actions and how to draw the button. main character delegation energy, honestly.
QButton provides both push and toggle buttons. The QRadioButton and QCheckBox classes provide only toggle buttons; QPushButton and QToolButton provide both toggle and push buttons.
Any button can have either a text or pixmap label. setText() sets the button to be a text button and setPixmap() sets it to be a pixmap button. The text/pixmap is manipulated as necessary to create the "disabled" appearance when the button is disabled.
QButton provides most of the states used for buttons, and here's the rundown β¨:
isDown()tells you whether the button is pressed down.isOn()tells you whether the button is on. Only toggle buttons can be switched on and off (see below).isEnabled()tells you whether the button can be pressed by the user.setAutoRepeat()sets whether the button will auto-repeat if the user holds it down.setToggleButton()sets whether the button is a toggle button or not.
The difference between isDown() and isOn() is as follows: When the user clicks a toggle button to toggle it on, the button is first pressed and then released into the on state. When the user clicks it again (to toggle it off), the button moves first to the pressed state, then to the off state (isOn() and isDown() are both FALSE). no cap, that's the whole arc π’
Default buttons (as used in many dialogs) are provided by QPushButton::setDefault() and QPushButton::setAutoDefault().
QButton provides five signals:
pressed()is emitted when the button is pressed. E.g. with the mouse or whenanimateClick()is called.released()is emitted when the button is released. E.g. when the mouse is released or the cursor is moved outside the widget.clicked()is emitted when the button is first pressed and then released when the accelerator key is typed, or whenanimateClick()is called.toggled(bool)is emitted when the state of a toggle button changes.stateChanged(int)is emitted when the state of a tristate toggle button changes.
If the button is a text button with an ampersand (&) in its text, QButton creates an automatic accelerator key. This code creates a push button labelled Ro<u>c</u>k & Roll (where the c is underlined). The button gets an automatic accelerator key, Alt+C:
QPushButton *p = new QPushButton( "Ro&ck && Roll", this );
In this example, when the user presses Alt+C the button will call animateClick().
You can also set a custom accelerator using the setAccel() function. This is useful mostly for pixmap buttons because they have no automatic accelerator.
p->setPixmap( QPixmap("print.png") );
p->setAccel( ALT+Key_F7 );
All of the buttons provided by Qt (QPushButton, QToolButton, QCheckBox and QRadioButton) can display both text and pixmaps.
To subclass QButton, you must reimplement at least drawButton() (to draw the button's outline) and drawButtonLabel() (to draw its text or pixmap). It is generally advisable to reimplement sizeHint() as well, and sometimes hitButton() (to determine whether a button press is within the button).
To reduce flickering, QButton::paintEvent() sets up a pixmap that the drawButton() function draws in. You should not reimplement paintEvent() for a subclass of QButton unless you want to take over all drawing. like, unless you're built different, don't π
See also QButtonGroup and Abstract Widget Classes.
π Member Type Documentation π
QButton::ToggleState
This enum defines the state of a toggle button.
QButton::Offβ the button is in the "off" stateQButton::NoChangeβ the button is in the default/unchanged stateQButton::Onβ the button is in the "on" state
QButton::ToggleType
This enum type defines what a button can do in response to a mouse/keyboard press:
QButton::SingleShotβ pressing the button causes an action, then the button returns to the unpressed state.QButton::Toggleβ pressing the button toggles it between an On and an Off state.QButton::Tristateβ pressing the button cycles between the three states On, Off and NoChange
β MEMBER FUNCTION DOCUMENTATION β
QButton::QButton ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
Constructs a standard button called name with parent parent, using the widget flags f.
If parent is a QButtonGroup, this constructor calls QButtonGroup::insert(). automatic group chat enrollment, love that for it π«Ά
QButton::~QButton ()
Destroys the button. rip little guy π
QKeySequence QButton::accel () const
Returns the accelerator associated with the button. See the "accel" property for details.
void QButton::animateClick () [slot]
Performs an animated click: the button is pressed and released a short while later.
The pressed(), released(), clicked(), toggled(), and stateChanged() signals are emitted as appropriate.
This function does nothing if the button is disabled.
See also accel.
bool QButton::autoRepeat () const
Returns TRUE if autoRepeat is enabled; otherwise returns FALSE. See the "autoRepeat" property for details.
bool QButton::autoResize () const
Returns TRUE if autoResize is enabled; otherwise returns FALSE. See the "autoResize" property for details.
void QButton::clicked () [signal]
This signal is emitted when the button is activated (i.e. first pressed down and then released when the mouse cursor is inside the button), when the accelerator key is typed or when animateClick() is called. This signal is not emitted if you call setDown().
The QButtonGroup::clicked() signal does the same job, if you want to connect several buttons to the same slot.
Warning: Don't launch a model dialog in response to this signal for a button that has autoRepeat turned on. fr fr, don't do it π
See also pressed(), released(), toggled(), autoRepeat, and down.
Examples:
void QButton::drawButton ( QPainter * ) [virtual protected]
Draws the button. The default implementation does nothing.
This virtual function is reimplemented by subclasses to draw real buttons. At some point, these reimplementations should call drawButtonLabel().
See also drawButtonLabel() and paintEvent().
void QButton::drawButtonLabel ( QPainter * ) [virtual protected]
Draws the button text or pixmap.
This virtual function is reimplemented by subclasses to draw real buttons. It is invoked by drawButton().
See also drawButton() and paintEvent().
QButtonGroup * QButton::group () const
Returns the group that this button belongs to.
If the button is not a member of any QButtonGroup, this function returns 0. (solo era π)
See also QButtonGroup.
bool QButton::hitButton ( const QPoint & pos ) const [virtual protected]
Returns TRUE if pos is inside the clickable button rectangle; otherwise returns FALSE.
By default, the clickable area is the entire widget. Subclasses may reimplement it, though.
bool QButton::isDown () const
Returns TRUE if the button is pressed; otherwise returns FALSE. See the "down" property for details.
bool QButton::isExclusiveToggle () const
Returns TRUE if the button is an exclusive toggle; otherwise returns FALSE. See the "exclusiveToggle" property for details.
bool QButton::isOn () const
Returns TRUE if the button is toggled; otherwise returns FALSE. See the "on" property for details.
bool QButton::isToggleButton () const
Returns TRUE if the button is a toggle button; otherwise returns FALSE. See the "toggleButton" property for details.
void QButton::paintEvent ( QPaintEvent * ) [virtual protected]
Handles paint events for buttons. Small and typically complex buttons are painted double-buffered to reduce flicker. The actually drawing is done in the virtual functions drawButton() and drawButtonLabel().
See also drawButton() and drawButtonLabel().
Reimplemented from QWidget.
const QPixmap * QButton::pixmap () const
Returns the pixmap shown on the button. See the "pixmap" property for details.
void QButton::pressed () [signal]
This signal is emitted when the button is pressed down.
See also released() and clicked().
Examples:
void QButton::released () [signal]
This signal is emitted when the button is released.
See also pressed(), clicked(), and toggled().
void QButton::setAccel ( const QKeySequence & ) [virtual]
Sets the accelerator associated with the button. See the "accel" property for details.
void QButton::setAutoRepeat ( bool ) [virtual]
Sets whether autoRepeat is enabled. See the "autoRepeat" property for details.
void QButton::setAutoResize ( bool ) π
Turns autoResize on or off, bestie. Wanna know what it actually does? Go peek at the "autoResize" property, it's all laid out there. β¨
void QButton::setDown ( bool ) [virtual]
Sets whether the button is pressed. Yeah, that's the whole thing β the "down" property has the deets. π«Ά
void QButton::setOn ( bool on ) [protected]
Okay so this one flips the vibe of your button: if on is TRUE the state goes to On, otherwise it goes to Off. That's it, that's the function. πΈ
See also toggleState.
void QButton::setPixmap ( const QPixmap & ) [virtual]
Sets the pixmap that gets shown on the button. Full story lives in the "pixmap" property. π
void QButton::setState ( ToggleState s ) [virtual protected]
Sets the toggle state of the button to s. And what can s be, you ask? Off, NoChange or On. That's the whole menu. π
void QButton::setText ( const QString & ) [virtual]
Sets the text shown on the button. The "text" property is where all the lore is. β¨
void QButton::setToggleButton ( bool b ) [protected]
If b is TRUE, this button becomes a toggle button. If b is FALSE, this button becomes a command button. Glow-up or glow-down, your call. π
See also toggleButton.
void QButton::setToggleType ( ToggleType type ) [virtual protected]
Sets the toggle type of the button to type.
And type can be set to SingleShot, Toggle and Tristate. Three flavours, pick your fighter. π₯
ToggleState QButton::state () const
Returns the state of the toggle button. The "toggleState" property is right there if you want more. π
void QButton::stateChanged ( int state ) [signal]
This signal goes off whenever a toggle button changes state. So state is On if the button is on, NoChange if it's in the "no change" state, or Off if the button is off. π
And like, this can happen because of a user action, because the toggle() slot got activated, because of setState(), or because setOn() was called. Any of those. Not me listing every possible source π
See also clicked() and QButton::ToggleState.
QString QButton::text () const
Returns the text shown on the button. "text" property, go read it, it's giving detail. π¦
void QButton::toggle () [slot]
Toggles the state of a toggle button. Flip it and reverse it. π
See also on, setOn(), toggled(), and toggleButton.
ToggleType QButton::toggleType () const
Returns the type of toggle on the button. The "toggleType" property has everything you need. β
void QButton::toggled ( bool on ) [signal]
This signal is emitted whenever a toggle button changes status. on is TRUE if the button is on, or FALSE if the button is off. Periodt.
This may be the result of a user action, toggle() slot activation, or because setOn() was called.
See also clicked().
Example: listbox/listbox.cpp.
π Property Documentation π
QKeySequence accel
This property holds the accelerator associated with the button.
It's 0 if there's no accelerator set. And if you set this property to 0, then any current accelerator gets removed. Poof, gone. π¨
Set this property's value with setAccel() and get this property's value with accel().
bool autoRepeat
This property holds whether autoRepeat is enabled.
If autoRepeat is enabled then the clicked() signal is emitted at regular intervals if the button is down. Heads up though: this property has no effect on toggle buttons. And autoRepeat is off by default, so it's lowkey just chilling. π
Set this property's value with setAutoRepeat() and get this property's value with autoRepeat().
bool autoResize
This property holds whether autoResize is enabled.
β οΈ Okay bestie, real talk: this property is obsolete. It's only provided to keep old source working. We strongly advise against using it in new code. Like, don't. π
If autoResize is enabled then the button will resize itself whenever the contents are changed.
Set this property's value with setAutoResize() and get this property's value with autoResize().
bool down
This property holds whether the button is pressed.
If this property is TRUE, the button is pressed down. But watch out β the pressed() and clicked() signals are not emitted if you set this property to TRUE. The default is FALSE. π
Set this property's value with setDown() and get this property's value with isDown().
bool exclusiveToggle
This property holds whether the button is an exclusive toggle.
If this property is TRUE and the button is in a QButtonGroup, the button can only be toggled off by another one being toggled on. The default is FALSE. β¨
Get this property's value with isExclusiveToggle().
bool on
This property holds whether the button is toggled.
This property should only be set for toggle buttons. Not command buttons. Just saying. π
Get this property's value with isOn().
QPixmap pixmap
This property holds the pixmap shown on the button.
If the pixmap is monochrome (i.e. it is a QBitmap or its depth is 1) and it does not have a mask, this property will set the pixmap to be its own mask. The purpose of this is to draw transparent bitmaps which are important for toggle buttons, for example. Iconic behaviour honestly. π
And heads up: pixmap() returns 0 if no pixmap was set.
Set this property's value with setPixmap() and get this property's value with pixmap().
QString text
This property holds the text shown on the button.
This property will return a QString::null if the button has no text. And okay this part is important β if the text has an ampersand (&) in it, then an accelerator is automatically created for it using the character that follows the '&' as the accelerator key. Any previous accelerator will be overwritten, or cleared if no accelerator is defined by the text. So don't be surprised when your old accel ghosts you. π»
There is no default text.
Set this property's value with setText() and get this property's value with text().
bool toggleButton
This property holds whether the button is a toggle button.
The default value is FALSE. π
Get this property's value with isToggleButton().
ToggleState toggleState
This property holds the state of the toggle button.
β οΈ If this property is changed then it does not cause the button to be repainted. So like, don't expect a visual glow-up for free. π
Get this property's value with state().
ToggleType toggleType
This property holds the type of toggle on the button.
The default toggle type is SingleShot. π
See also QButton::ToggleType.
Get this property's value with toggleType().
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
βοΈ AUTHOR βοΈ
Generated automatically from the source code. (No human ghostwrote this, it literally spawned from the code itself, main character energy tbh π )
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. π«Ά
The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. So like, it's a vibe, not a promise. π
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qbutton.3qt) and the Qt version (3.3.8). Fr fr, include those, it helps so much. π
aaaand that's a wrap bestie!! πβ¨ This lil doc came from the Trolltech AS girlies on 2 February 2007, and it's the QButton(3qt) page β 3.3.8 era, iconic behaviour, no cap. Go forth and toggle responsibly. π
ππ¦
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms