QPushButton(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ’– QPushButton πŸ’– β€” straight from the 3qt manual, bestie


✨ NAME ✨

QPushButton β€” the Command button. That's it, that's the whole vibe. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <qpushbutton.h>

Inherits QButton. It's giving "I'm a button and I know it". πŸ‘‘

πŸ’œ Public Members

  • QPushButton ( QWidget * parent, const char * name = 0 )
  • QPushButton ( const QString & text, QWidget * parent, const char * name = 0 )
  • QPushButton ( const QIconSet & icon, const QString & text, QWidget * parent, const char * name = 0 )
  • ~QPushButton ()
  • void setToggleButton ( bool )
  • bool autoDefault () const
  • virtual void setAutoDefault ( bool autoDef )
  • bool isDefault () const
  • virtual void setDefault ( bool def )
  • virtual void setIsMenuButton ( bool enable ) β€” (obsolete, rip πŸͺ¦)
  • bool isMenuButton () const β€” (obsolete, also rip πŸͺ¦)
  • void setPopup ( QPopupMenu * popup )
  • QPopupMenu * popup () const
  • void setIconSet ( const QIconSet & )
  • QIconSet * iconSet () const
  • void setFlat ( bool )
  • bool isFlat () const

🌸 Public Slots

  • virtual void setOn ( bool )

🌈 Important Inherited Members

  • QString text () const
  • virtual void setText ( const QString & )
  • const QPixmap * pixmap () const
  • virtual void setPixmap ( const QPixmap & )
  • QKeySequence accel () const
  • virtual void setAccel ( const QKeySequence & )
  • bool isToggleButton () const
  • virtual void setDown ( bool )
  • bool isDown () const
  • bool isOn () const
  • ToggleState state () const
  • bool autoRepeat () const
  • virtual void setAutoRepeat ( bool )
  • bool isExclusiveToggle () const
  • QButtonGroup * group () const
  • void toggle ()
  • void pressed ()
  • void released ()
  • void clicked ()
  • void toggled ( bool on )
  • void stateChanged ( int state )

πŸ¦‹ Properties

  • bool autoDefault β€” whether the push button is the auto default button
  • bool autoMask β€” whether the button is automatically masked (read only)
  • bool default β€” whether the push button is the default button
  • bool flat β€” whether the border is disabled
  • QIconSet iconSet β€” the icon set on the push button
  • bool menuButton β€” whether the push button has a menu button on it (read only) (obsolete)
  • bool on β€” whether the push button is toggled
  • bool toggleButton β€” whether the button is a toggle button

πŸ¦‹ DESCRIPTION πŸ¦‹

The QPushButton widget provides a command button. ✨

The push button, aka the command button, is lowkey the most used widget in any graphical user interface, no cap. You push (click) a button to command the computer to do a thing, or to answer a question. Classic buttons are OK, Apply, Cancel, Close, Yes, No and Help β€” the whole squad. πŸ’–

A command button is rectangular and typically displays a text label describing its action. An underlined character in the label (signified by preceding it with an ampersand in the text) indicates an accelerator key, e.g.

QPushButton *pb = new QPushButton( "&Download", this );

In this example the accelerator is Alt+D, and the label text will be displayed as <u>D</u>ownload. The way that ampersand just does that? Iconic. πŸŽ€

Push buttons can display a textual label or a pixmap, and optionally a small icon. These can be set using the constructors and changed later using setText(), setPixmap() and setIconSet(). If the button is disabled the appearance of the text or pixmap and iconset will be manipulated with respect to the GUI style to make the button look "disabled". It's giving sad gray button energy, honestly. πŸ™ˆ

A push button emits the signal clicked() when it is activated by the mouse, the Spacebar or by a keyboard accelerator. Connect to this signal to perform the button's action. Push buttons also provide less commonly used signals, for example, pressed() and released().

Command buttons in dialogs are by default auto-default buttons, i.e. they become the default push button automatically when they receive the keyboard input focus. A default button is a push button that is activated when the user presses the Enter or Return key in a dialog. You can change this with setAutoDefault(). Note that auto-default buttons reserve a little extra space which is necessary to draw a default-button indicator. If you do not want this space around your buttons, call setAutoDefault(FALSE).

Being so central, the button widget has grown to accommodate a great many variations in the past decade. The Microsoft style guide now shows about ten different states of Windows push buttons and the text implies that there are dozens more when all the combinations of features are taken into consideration. Like... that's a lot of button, bestie. 😭

The most important modes or states are:

  • Available or not (grayed out, disabled).
  • Standard push button, toggling push button or menu button.
  • On or off (only for toggling push buttons).
  • Default or normal. The default button in a dialog can generally be "clicked" using the Enter or Return key.
  • Auto-repeat or not.
  • Pressed down or not.

As a general rule, use a push button when the application or dialog window performs an action when the user clicks on it (such as Apply, Cancel, Close and Help) and when the widget is supposed to have a wide, rectangular shape with a text label. Small, typically square buttons that change the state of the window rather than performing an action (such as the buttons in the top-right corner of the QFileDialog) are not command buttons, but tool buttons. Qt provides a special class (QToolButton) for these buttons. Know the difference, it matters. πŸ’…

If you need toggle behavior (see setToggleButton()) or a button that auto-repeats the activation signal when being pushed down like the arrows in a scroll bar (see setAutoRepeat()), a command button is probably not what you want. When in doubt, use a tool button.

A variation of a command button is a menu button. These provide not just one command, but several, since when they are clicked they pop up a menu of options. Use the method setPopup() to associate a popup menu with a push button. Main character menu energy. πŸ‘‘

Other classes of buttons are option buttons (see QRadioButton) and check boxes (see QCheckBox).

[Image Omitted]

[Image Omitted]

In Qt, the QButton abstract base class provides most of the modes and other API, and QPushButton provides GUI logic. See QButton for more information about the API.

See also QToolButton, QRadioButton, QCheckBox, GUI Design Handbook: Push Button, and Basic Widgets.


πŸ’… MEMBER FUNCTION DOCUMENTATION πŸ’…

QPushButton::QPushButton ( QWidget * parent, const char * name = 0 )

Constructs a push button with no text. A blank canvas, a fresh start, a baby button. 🐣

The parent and name arguments are sent on to the QWidget constructor.

QPushButton::QPushButton ( const QString & text, QWidget * parent, const char * name = 0 )

Constructs a push button called name with the parent parent and the text text.

QPushButton::QPushButton ( const QIconSet & icon, const QString & text, QWidget * parent, const char * name = 0 )

Constructs a push button with an icon and a text. Glow-up complete. ✨

Note that you can also pass a QPixmap object as an icon (thanks to the implicit type conversion provided by C++).

The parent and name arguments are sent to the QWidget constructor.

QPushButton::~QPushButton ()

Destroys the push button. Gone but not forgotten. 🫢

QKeySequence QButton::accel () const

Returns the accelerator associated with the button. See the "accel" property for details.

bool QPushButton::autoDefault () const

Returns TRUE if the push button is the auto default button; otherwise returns FALSE. See the "autoDefault" property for details.

bool QButton::autoRepeat () const

Returns TRUE if autoRepeat is enabled; otherwise returns FALSE. See the "autoRepeat" 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. Just don't. That's chaos. πŸ’€

See also pressed(), released(), toggled(), autoRepeat, and down.

Examples:

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.

See also QButtonGroup.

QIconSet * QPushButton::iconSet () const

Returns the icon set on the push button. See the "iconSet" property for details.

bool QPushButton::isDefault () const

Returns TRUE if the push button is the default button; otherwise returns FALSE. See the "default" property for details.

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 QPushButton::isFlat () const

Returns TRUE if the border is disabled; otherwise returns FALSE. See the "flat" property for details.

bool QPushButton::isMenuButton () const

Returns TRUE if the push button has a menu button on it; otherwise returns FALSE. See the "menuButton" 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.

const QPixmap * QButton::pixmap () const

Returns the pixmap shown on the button. See the "pixmap" property for details.

QPopupMenu * QPushButton::popup () const

Returns the button's associated popup menu or 0 if no popup menu has been set.

See also setPopup().

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 QPushButton::setAutoDefault ( bool autoDef ) [virtual]

Sets whether the push button is the auto default button to autoDef. See the "autoDefault" property for details.

void QButton::setAutoRepeat ( bool ) [virtual]

Sets whether autoRepeat is enabled. See the "autoRepeat" property for details.

void QPushButton::setDefault ( bool def ) [virtual]

Sets whether the push button is the default button to def. See the "default" property for details.

void QButton::setDown ( bool ) [virtual]

Sets whether the button is pressed. See the "down" property for details.

void QPushButton::setFlat ( bool )

Sets whether the border is disabled. See the "flat" property for details.

void QPushButton::setIconSet ( const QIconSet & )

Puts an icon set on the push button, bestie. That's the whole job. All the deets live over in the iconSet property if you wanna go deeper πŸ’…


void QPushButton::setIsMenuButton ( bool enable ) [virtual]

Ok so this one is obsolete 🫠 It's only still here so ancient source code doesn't break. The Qt girlies strongly advise against using it in new code β€” like, do not. Periodt.


void QPushButton::setOn ( bool ) [virtual slot]

Sets whether the push button is toggled on or not. The full story is in the on property ✨


void QButton::setPixmap ( const QPixmap & ) [virtual]

Sets the pixmap that shows up on the button. Head over to the pixmap property for the details 🌸


void QPushButton::setPopup ( QPopupMenu * popup )

Associates the popup menu popup with this push button β€” which is literally what turns the button into a menu button πŸ’…

🚨 Bestie listen: ownership of the popup menu is not transferred to the push button. It stays yours. You handle it.

See also popup().

Examples:

(so the man page said "Examples:" and then just… didn't give us any πŸ™ˆ the audacity honestly)


void QButton::setText ( const QString & ) [virtual]

Sets the text shown on the button. Yeah, it's in the text property, go look πŸŽ€


void QPushButton::setToggleButton ( bool )

Sets whether the button is a toggle button. The toggleButton property has the tea β˜•


ToggleState QButton::state () const

Returns the state of the toggle button. Everything about it lives in the toggleState property πŸ’–


void QButton::stateChanged ( int state ) [signal]

This signal fires whenever a toggle button changes state πŸ”₯ So state is:

  • On if the button is on
  • NoChange if it's in the "no change" state
  • Off if the button is off

And it can be triggered by a user action, by activating the toggle() slot, by setState(), or because setOn() got called. Main character signal energy, no cap.

See also clicked() and QButton::ToggleState.


QString QButton::text () const

Returns the text shown on the button. Yes, the text property, we been knew πŸ’œ


void QButton::toggle () [slot]

Toggles the state of a toggle button. That's it, that's the function πŸ¦‹

See also on, on, toggled(), and toggleButton.


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

Fires whenever a toggle button changes status ✨ on is TRUE if the button is on, and FALSE if the button is off.

Could be from a user action, from activating the toggle() slot, 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, any current accelerator gets removed β€” gone, ghosted, bye 🫢

Set it with setAccel() and read it back with accel().


bool autoDefault

This property holds whether the push button is the auto default button πŸ‘‘

Set it to TRUE and the push button becomes the auto default button in a dialog.

Heads up though: in some GUI styles a default button is drawn with an extra frame around it β€” up to 3 pixels or more. Qt automatically keeps that space free around auto-default buttons, i.e. auto-default buttons may have a slightly larger size hint πŸ“

Default value? TRUE for buttons that have a QDialog parent; otherwise it defaults to FALSE.

See the default property for details of how default and auto-default interact πŸ‘€

Set it with setAutoDefault() and get it with autoDefault().


bool autoMask

This property holds whether the button is automatically masked 🎭

See also QWidget::autoMask.


bool autoRepeat

This property holds whether autoRepeat is enabled πŸ”

If autoRepeat is enabled, the clicked() signal gets emitted at regular intervals while the button is down. Important: this property has no effect on toggle buttons. And autoRepeat is off by default.

Set it with setAutoRepeat() and get it with autoRepeat().


bool default

This property holds whether the push button is the default button ⭐

Set it to TRUE and the push button will be pressed when the user hits the Enter (or Return) key in a dialog.

Regardless of focus, if the user presses Enter:

  • If there is a default button, the default button is pressed.
  • Otherwise, if there are one or more autoDefault buttons, the first autoDefault button that is next in the tab order is pressed.
  • If there are no default or autoDefault buttons, only pressing Space on a button with focus, mouse clicking, or using an accelerator will press a button.

In a dialog, only one push button at a time can be the default button. That button is then displayed with an additional frame (depending on the GUI style) πŸ’…

Also: the default button behavior is provided only in dialogs. Buttons can always be clicked from the keyboard by pressing Enter (or Return) or the Spacebar when the button has focus.

Default value is FALSE.

Set it with setDefault() and get it with isDefault().


bool flat

This property holds whether the border is disabled 🚫

Default value is FALSE.

Set it with setFlat() and get it with isFlat().


QIconSet iconSet

This property holds the icon set on the push button πŸŽ€

It returns 0 if the push button has no iconset.

Set it with setIconSet() and get it with iconSet().


bool menuButton

This property holds whether the push button has a menu button on it.

Ok so: this property is obsolete πŸ’€ It's provided just to keep old source working, and we strongly advise against using it in new code.

If you set it to TRUE, a down arrow gets drawn on the push button to indicate that a menu will pop up if the user clicks on the arrow πŸ”½

Get this property's value with isMenuButton().


bool on

This property holds whether the push button is toggled πŸ’–

Only set this for toggle push buttons, bestie β€” not for regular ones. The default value is FALSE.

See also on, toggle(), toggled(), and toggleButton.

Set this property's value with setOn().


QPixmap pixmap

This property holds the pixmap shown on the button 🌸

Here's the tea: 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. Why? To draw transparent bitmaps, which is important for toggle buttons, for example ✨

pixmap() returns 0 if no pixmap was set.

Set it with setPixmap() and get it with pixmap().


QString text

This property holds the text shown on the button πŸŽ€

It'll return a QString::null if the button has no text. And if the text has an ampersand (&) in it, an accelerator is automatically created for it using the character that follows the & as the accelerator key. Any previous accelerator gets overwritten β€” or cleared if no accelerator is defined by the text.

There is no default text.

Set it with setText() and get it with text().


bool toggleButton

This property holds whether the button is a toggle button πŸ’…

Toggle buttons have an on/off state, similar to check boxes. A push button is initially not a toggle button.

See also on, toggle(), toggleButton, and toggled().

Set this property's value with setToggleButton().


πŸ‘€ SEE ALSO πŸ‘€


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. (Not a human, not a girlie, just a script doing its thing 🧚)


πŸ› 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 🌈

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qpushbutton.3qt) and the Qt version (3.3.8).


And that's a wrap bestie!! πŸ’– This lil' page came from Trolltech AS, dated 2 February 2007, and it's living under the name QPushButton(3qt). Slay, go press some buttons βœ¨πŸ‘‘

πŸ“¦ where this page comes from