Qt 4.8
Public Slots | Public Functions | Protected Functions | Properties | List of all members
QPushButton Class Reference

The QPushButton widget provides a command button. More...

#include <qpushbutton.h>

Inheritance diagram for QPushButton:
QAbstractButton QWidget QObject QPaintDevice DetailButton QCommandLinkButton

Public Slots

void showMenu ()
 Shows (pops up) the associated popup menu. More...
 
- Public Slots inherited from QAbstractButton
void animateClick (int msec=100)
 Performs an animated click: the button is pressed immediately, and released msec milliseconds later (the default is 100 ms). More...
 
void click ()
 Performs a click. More...
 
void setChecked (bool)
 
void setIconSize (const QSize &size)
 
void toggle ()
 Toggles the state of a checkable button. More...
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Public Functions

bool autoDefault () const
 
bool isDefault () const
 
bool isFlat () const
 
QMenumenu () const
 Returns the button's associated popup menu or 0 if no popup menu has been set. More...
 
QSize minimumSizeHint () const
 Reimplemented Function More...
 
 QPushButton (QWidget *parent=0)
 Constructs a push button with no text and a parent. More...
 
 QPushButton (const QString &text, QWidget *parent=0)
 Constructs a push button with the parent parent and the text text. More...
 
 QPushButton (const QIcon &icon, const QString &text, QWidget *parent=0)
 Constructs a push button with an icon and a text, and a parent. More...
 
void setAutoDefault (bool)
 
void setDefault (bool)
 
void setFlat (bool)
 
void setMenu (QMenu *menu)
 Associates the popup menu menu with this push button. More...
 
QSize sizeHint () const
 Reimplemented Function More...
 
 ~QPushButton ()
 Destroys the push button. More...
 
- Public Functions inherited from QAbstractButton
bool autoExclusive () const
 
bool autoRepeat () const
 
int autoRepeatDelay () const
 
int autoRepeatInterval () const
 
QButtonGroupgroup () const
 Returns the group that this button belongs to. More...
 
QIcon icon () const
 
QSize iconSize () const
 
bool isCheckable () const
 
bool isChecked () const
 
bool isDown () const
 
 QAbstractButton (QWidget *parent=0)
 Constructs an abstract button with a parent. More...
 
void setAutoExclusive (bool)
 
void setAutoRepeat (bool)
 
void setAutoRepeatDelay (int)
 
void setAutoRepeatInterval (int)
 
void setCheckable (bool)
 
void setDown (bool)
 
void setIcon (const QIcon &icon)
 
void setShortcut (const QKeySequence &key)
 
void setText (const QString &text)
 
QKeySequence shortcut () const
 
QString text () const
 
 ~QAbstractButton ()
 Destroys the button. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w. More...
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery) const
 This method is only relevant for input widgets. More...
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
QPaintEnginepaintEngine () const
 Returns the widget's paint engine. More...
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
void setWhatsThis (const QString &)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags type)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowIconText (const QString &)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Protected Functions

bool event (QEvent *e)
 Reimplemented Function More...
 
void focusInEvent (QFocusEvent *)
 Reimplemented Function More...
 
void focusOutEvent (QFocusEvent *)
 Reimplemented Function More...
 
bool hitButton (const QPoint &pos) const
 Reimplemented Function More...
 
void initStyleOption (QStyleOptionButton *option) const
 Initialize option with the values from this QPushButton. More...
 
void keyPressEvent (QKeyEvent *)
 Reimplemented Function More...
 
void paintEvent (QPaintEvent *)
 Reimplemented Function More...
 
 QPushButton (QPushButtonPrivate &dd, QWidget *parent=0)
 
- Protected Functions inherited from QAbstractButton
void changeEvent (QEvent *e)
 Reimplemented Function More...
 
virtual void checkStateSet ()
 This virtual handler is called when setChecked() was called, unless it was called from within nextCheckState(). More...
 
void keyReleaseEvent (QKeyEvent *e)
 Reimplemented Function More...
 
void mouseMoveEvent (QMouseEvent *e)
 Reimplemented Function More...
 
void mousePressEvent (QMouseEvent *e)
 Reimplemented Function More...
 
void mouseReleaseEvent (QMouseEvent *e)
 Reimplemented Function More...
 
virtual void nextCheckState ()
 This virtual handler is called when a button is clicked. More...
 
 QAbstractButton (QAbstractButtonPrivate &dd, QWidget *parent=0)
 
void timerEvent (QTimerEvent *e)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QWidget
virtual void actionEvent (QActionEvent *)
 This event handler is called with the given event whenever the widget's actions are changed. More...
 
virtual void closeEvent (QCloseEvent *)
 This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system. More...
 
virtual void contextMenuEvent (QContextMenuEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive widget context menu events. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void dragEnterEvent (QDragEnterEvent *)
 This event handler is called when a drag is in progress and the mouse enters this widget. More...
 
virtual void dragLeaveEvent (QDragLeaveEvent *)
 This event handler is called when a drag is in progress and the mouse leaves this widget. More...
 
virtual void dragMoveEvent (QDragMoveEvent *)
 This event handler is called if a drag is in progress, and when any of the following conditions occur: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. More...
 
virtual void dropEvent (QDropEvent *)
 This event handler is called when the drag is dropped on this widget. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual bool focusNextPrevChild (bool next)
 Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void hideEvent (QHideEvent *)
 This event handler can be reimplemented in a subclass to receive widget hide events. More...
 
virtual void inputMethodEvent (QInputMethodEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive Input Method composition events. More...
 
virtual void languageChange ()
 
virtual void leaveEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter. More...
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void mouseDoubleClickEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void resizeEvent (QResizeEvent *)
 This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. More...
 
virtual void showEvent (QShowEvent *)
 This event handler can be reimplemented in a subclass to receive widget show events which are passed in the event parameter. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void wheelEvent (QWheelEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive wheel events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

bool autoDefault
 whether the push button is an auto default button More...
 
bool default
 whether the push button is the default button More...
 
bool flat
 whether the button border is raised More...
 

Additional Inherited Members

- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 
- Signals inherited from QAbstractButton
void clicked (bool checked=false)
 This signal is emitted when the button is activated (i.e. More...
 
void pressed ()
 This signal is emitted when the button is pressed down. More...
 
void released ()
 This signal is emitted when the button is released. More...
 
void toggled (bool checked)
 This signal is emitted whenever a checkable button changes its state. More...
 
- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QPushButton widget provides a command button.

The push button, or command button, is perhaps the most commonly used widget in any graphical user interface. Push (click) a button to command the computer to perform some action, or to answer a question. Typical buttons are OK, Apply, Cancel, Close, Yes, No and Help.

A command button is rectangular and typically displays a text label describing its action. A shortcut key can be specified by preceding the preferred character with an ampersand in the text. For example:

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

In this example the shortcut is Alt+D. See the QShortcut documentation for details (to display an actual ampersand, use '&&').

Push buttons display a textual label, and optionally a small icon. These can be set using the constructors and changed later using setText() and setIcon(). If the button is disabled the appearance of the text and icon will be manipulated with respect to the GUI style to make the button look "disabled".

A push button emits the signal clicked() when it is activated by the mouse, the Spacebar or by a keyboard shortcut. 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.

The most important modes or states are:

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.

If you need toggle behavior (see setCheckable()) 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 setMenu() to associate a popup menu with a push button.

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

macintosh-pushbutton.png
Screenshot of a Macintosh style push button

A push button shown in the Macintosh Style Widget Gallery{Macintosh widget style}.

Note that when a button's width becomes smaller than 50 or its height becomes smaller than 30, the button's corners are changed from round to square. Use the setMinimumSize() function to prevent this behavior.

windowsxp-pushbutton.png
Screenshot of a Windows XP style push button
A push button shown in the Windows XP Style Widget Gallery{Windows XP widget style}.
plastique-pushbutton.png
Screenshot of a Plastique style push button
A push button shown in the Plastique Style Widget Gallery{Plastique widget style}.

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

See also
QToolButton, QRadioButton, QCheckBox, {fowler}{GUI Design Handbook: Push Button}

Definition at line 57 of file qpushbutton.h.

Constructors and Destructors

◆ QPushButton() [1/4]

QPushButton::QPushButton ( QWidget parent = 0)
explicit

Constructs a push button with no text and a parent.

Definition at line 257 of file qpushbutton.cpp.

Referenced by QPushButtonPrivate::hitButton().

258  : QAbstractButton(*new QPushButtonPrivate, parent)
259 {
260  Q_D(QPushButton);
261  d->init();
262 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton(QWidget *parent=0)
Constructs an abstract button with a parent.

◆ QPushButton() [2/4]

QPushButton::QPushButton ( const QString text,
QWidget parent = 0 
)
explicit

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

Definition at line 269 of file qpushbutton.cpp.

270  : QAbstractButton(*new QPushButtonPrivate, parent)
271 {
272  Q_D(QPushButton);
273  setText(text);
274  d->init();
275 }
double d
Definition: qnumeric_p.h:62
void setText(const QString &text)
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton(QWidget *parent=0)
Constructs an abstract button with a parent.

◆ QPushButton() [3/4]

QPushButton::QPushButton ( const QIcon icon,
const QString text,
QWidget parent = 0 
)

Constructs a push button with an icon and a text, and a parent.

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

Definition at line 285 of file qpushbutton.cpp.

286  : QAbstractButton(*new QPushButtonPrivate, parent)
287 {
288  Q_D(QPushButton);
289  setText(text);
290  setIcon(icon);
291  d->init();
292 }
double d
Definition: qnumeric_p.h:62
void setText(const QString &text)
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton(QWidget *parent=0)
Constructs an abstract button with a parent.
void setIcon(const QIcon &icon)

◆ ~QPushButton()

QPushButton::~QPushButton ( )

Destroys the push button.

Definition at line 306 of file qpushbutton.cpp.

307 {
308 }

◆ QPushButton() [4/4]

QPushButton::QPushButton ( QPushButtonPrivate dd,
QWidget parent = 0 
)
protected
Warning
This function is not part of the public interface.

Definition at line 296 of file qpushbutton.cpp.

297  : QAbstractButton(dd, parent)
298 {
299  Q_D(QPushButton);
300  d->init();
301 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton(QWidget *parent=0)
Constructs an abstract button with a parent.

Functions

◆ autoDefault()

bool QPushButton::autoDefault ( ) const

◆ event()

bool QPushButton::event ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractButton.

Definition at line 676 of file qpushbutton.cpp.

Referenced by QCommandLinkButton::event().

677 {
678  Q_D(QPushButton);
679  if (e->type() == QEvent::ParentChange) {
680  if (QDialog *dialog = d->dialogParent()) {
681  if (d->defaultButton)
682  dialog->d_func()->setMainDefault(this);
683  }
684  } else if (e->type() == QEvent::StyleChange
685 #ifdef Q_WS_MAC
686  || e->type() == QEvent::MacSizeChange
687 #endif
688  ) {
689  d->resetLayoutItemMargins();
690  updateGeometry();
691  } else if (e->type() == QEvent::PolishRequest) {
692  updateGeometry();
693  }
694  return QAbstractButton::event(e);
695 }
double d
Definition: qnumeric_p.h:62
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
bool event(QEvent *e)
Reimplemented Function
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ focusInEvent()

void QPushButton::focusInEvent ( QFocusEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractButton.

Definition at line 489 of file qpushbutton.cpp.

490 {
491  Q_D(QPushButton);
492  if (e->reason() != Qt::PopupFocusReason && autoDefault() && !d->defaultButton) {
493  d->defaultButton = true;
494  QDialog *dlg = qobject_cast<QDialog*>(window());
495  if (dlg)
496  dlg->d_func()->setDefault(this);
497  }
499 }
double d
Definition: qnumeric_p.h:62
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
bool autoDefault() const
void focusInEvent(QFocusEvent *e)
Reimplemented Function
Qt::FocusReason reason()
Definition: qevent.cpp:1197
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492

◆ focusOutEvent()

void QPushButton::focusOutEvent ( QFocusEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractButton.

Definition at line 504 of file qpushbutton.cpp.

505 {
506  Q_D(QPushButton);
507  if (e->reason() != Qt::PopupFocusReason && autoDefault() && d->defaultButton) {
508  QDialog *dlg = qobject_cast<QDialog*>(window());
509  if (dlg)
510  dlg->d_func()->setDefault(0);
511  else
512  d->defaultButton = false;
513  }
514 
516 #ifndef QT_NO_MENU
517  if (d->menu && d->menu->isVisible()) // restore pressed status
518  setDown(true);
519 #endif
520 }
double d
Definition: qnumeric_p.h:62
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
bool autoDefault() const
void focusOutEvent(QFocusEvent *e)
Reimplemented Function
Qt::FocusReason reason()
Definition: qevent.cpp:1197
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492

◆ hitButton()

bool QPushButton::hitButton ( const QPoint pos) const
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractButton.

Definition at line 699 of file qpushbutton.cpp.

700 {
701  QStyleOptionButton opt;
702  initStyleOption(&opt);
703  if (qt_mac_buttonIsRenderedFlat(this, &opt))
704  return QAbstractButton::hitButton(pos);
705 
706  // Now that we know we are using the native style, let's proceed.
707  Q_D(const QPushButton);
708  QPushButtonPrivate *nonConst = const_cast<QPushButtonPrivate *>(d);
709  // In OSX buttons are round, which causes the hit method to be special.
710  // We cannot simply relay on detecting if something is inside the rect or not,
711  // we need to check if it is inside the "rounded area" or not. A point might
712  // be inside the rect but not inside the rounded area.
713  // Notice this method is only reimplemented for OSX.
714  return nonConst->hitButton(pos);
715 }
double d
Definition: qnumeric_p.h:62
bool hitButton(const QPoint &pos)
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
void initStyleOption(QStyleOptionButton *option) const
Initialize option with the values from this QPushButton.
bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option)
virtual bool hitButton(const QPoint &pos) const
Returns true if pos is inside the clickable button rectangle; otherwise returns false.
The QStyleOptionButton class is used to describe the parameters for drawing buttons.
Definition: qstyleoption.h:279

◆ initStyleOption()

void QPushButton::initStyleOption ( QStyleOptionButton option) const
protected

Initialize option with the values from this QPushButton.

This method is useful for subclasses when they need a QStyleOptionButton, but don't want to fill in all the information themselves.

See also
QStyleOption::initFrom()

Definition at line 329 of file qpushbutton.cpp.

Referenced by hitButton(), QCommandLinkButton::paintEvent(), paintEvent(), and sizeHint().

330 {
331  if (!option)
332  return;
333 
334  Q_D(const QPushButton);
335  option->initFrom(this);
337  if (d->flat)
339 #ifndef QT_NO_MENU
340  if (d->menu)
342 #endif
343  if (autoDefault() || d->defaultButton)
345  if (d->defaultButton)
347  if (d->down || d->menuOpen)
348  option->state |= QStyle::State_Sunken;
349  if (d->checked)
350  option->state |= QStyle::State_On;
351  if (!d->flat && !d->down)
352  option->state |= QStyle::State_Raised;
353  option->text = d->text;
354  option->icon = d->icon;
355  option->iconSize = iconSize();
356 }
QSize iconSize
the size of the icon for the button
Definition: qstyleoption.h:292
double d
Definition: qnumeric_p.h:62
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
QString text
the text of the button
Definition: qstyleoption.h:290
#define Q_D(Class)
Definition: qglobal.h:2482
bool autoDefault() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
QIcon icon
the icon of the button
Definition: qstyleoption.h:291
ButtonFeatures features
a bitwise OR of the features that describe this button
Definition: qstyleoption.h:289
QSize iconSize() const

◆ isDefault()

bool QPushButton::isDefault ( ) const

Definition at line 394 of file qpushbutton.cpp.

Referenced by QDialogButtonBox::event(), QMacStylePrivate::eventFilter(), QDialog::keyPressEvent(), QAccessibleButton::state(), QAccessibleButton::text(), and QMacStylePrivate::timerEvent().

395 {
396  Q_D(const QPushButton);
397  return d->defaultButton;
398 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isFlat()

bool QPushButton::isFlat ( ) const

Definition at line 669 of file qpushbutton.cpp.

670 {
671  Q_D(const QPushButton);
672  return d->flat;
673 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482

◆ keyPressEvent()

void QPushButton::keyPressEvent ( QKeyEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractButton.

Definition at line 470 of file qpushbutton.cpp.

471 {
472  Q_D(QPushButton);
473  switch (e->key()) {
474  case Qt::Key_Enter:
475  case Qt::Key_Return:
476  if (autoDefault() || d->defaultButton) {
477  click();
478  break;
479  }
480  // fall through
481  default:
483  }
484 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
bool autoDefault() const
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
void keyPressEvent(QKeyEvent *e)
Reimplemented Function
void click()
Performs a click.

◆ menu()

QMenu * QPushButton::menu ( ) const

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

See also
setMenu()

Definition at line 567 of file qpushbutton.cpp.

Referenced by QPushButtonPrivate::_q_popupPressed(), QPushButtonPrivate::adjustedMenuPosition(), AccessibleFactory::create(), QAccessibleButton::doAction(), setMenu(), sizeHint(), and QAccessibleButton::state().

568 {
569  Q_D(const QPushButton);
570  return d->menu;
571 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482

◆ minimumSizeHint()

QSize QPushButton::minimumSizeHint ( ) const
virtual

Reimplemented Function

em>Reimplemented Function

Reimplemented from QWidget.

Definition at line 452 of file qpushbutton.cpp.

◆ paintEvent()

void QPushButton::paintEvent ( QPaintEvent e)
protectedvirtual

Reimplemented Function

Implements QAbstractButton.

Definition at line 460 of file qpushbutton.cpp.

461 {
462  QStylePainter p(this);
463  QStyleOptionButton option;
464  initStyleOption(&option);
465  p.drawControl(QStyle::CE_PushButton, option);
466 }
void initStyleOption(QStyleOptionButton *option) const
Initialize option with the values from this QPushButton.
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
The QStyleOptionButton class is used to describe the parameters for drawing buttons.
Definition: qstyleoption.h:279

◆ setAutoDefault()

void QPushButton::setAutoDefault ( bool  enable)

Definition at line 358 of file qpushbutton.cpp.

Referenced by QWizardPrivate::ensureButton().

359 {
360  Q_D(QPushButton);
362  if (d->autoDefault != QPushButtonPrivate::Auto && d->autoDefault == state)
363  return;
364  d->autoDefault = state;
365  d->sizeHint = QSize();
366  update();
367  updateGeometry();
368 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
unsigned int uint
Definition: qglobal.h:996
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ setDefault()

void QPushButton::setDefault ( bool  enable)

Definition at line 378 of file qpushbutton.cpp.

Referenced by QPrintPropertiesDialog::addItemToOptions(), QDialogButtonBox::event(), QDialogPrivate::hideDefault(), QFontDialogPrivate::init(), QDialogPrivate::setDefault(), QMessageBox::setDefaultButton(), QDialog::setVisible(), and QCoreFuriCuri::timerEvent().

379 {
380  Q_D(QPushButton);
381  if (d->defaultButton == enable)
382  return;
383  d->defaultButton = enable;
384  if (d->defaultButton) {
385  if (QDialog *dlg = d->dialogParent())
386  dlg->d_func()->setMainDefault(this);
387  }
388  update();
389 #ifndef QT_NO_ACCESSIBILITY
391 #endif
392 }
double d
Definition: qnumeric_p.h:62
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883

◆ setFlat()

void QPushButton::setFlat ( bool  flat)

Definition at line 657 of file qpushbutton.cpp.

658 {
659  Q_D(QPushButton);
660  if (d->flat == flat)
661  return;
662  d->flat = flat;
663  d->resetLayoutItemMargins();
664  d->sizeHint = QSize();
665  update();
666  updateGeometry();
667 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
bool flat
whether the button border is raised
Definition: qpushbutton.h:63
#define Q_D(Class)
Definition: qglobal.h:2482
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ setMenu()

void QPushButton::setMenu ( QMenu menu)

Associates the popup menu menu with this push button.

This turns the button into a menu button, which in some styles will produce a small triangle to the right of the button's text.

Ownership of the menu is not transferred to the push button.

plastique-pushbutton-menu.png
Screenshot of a Plastique style push button with popup menu.
cleanlooks-pushbutton-menu.png
Screenshot of a Cleanlooks style push button with popup menu.
Push buttons with popup menus shown in the Plastique Style Widget Gallery{Plastique widget style} (left) and Cleanlooks Style Widget Gallery{Cleanlooks widget style} (right).
See also
menu()

Definition at line 540 of file qpushbutton.cpp.

541 {
542  Q_D(QPushButton);
543  if (menu == d->menu)
544  return;
545 
546  if (menu && !d->menu) {
547  connect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed()), Qt::UniqueConnection);
548  }
549  if (d->menu)
550  removeAction(d->menu->menuAction());
551  d->menu = menu;
552  if (d->menu)
553  addAction(d->menu->menuAction());
554 
555  d->resetLayoutItemMargins();
556  d->sizeHint = QSize();
557  update();
558  updateGeometry();
559 }
double d
Definition: qnumeric_p.h:62
#define SLOT(a)
Definition: qobjectdefs.h:226
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
void pressed()
This signal is emitted when the button is pressed down.
#define Q_D(Class)
Definition: qglobal.h:2482
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
Definition: qwidget.cpp:3317
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QMenu * menu() const
Returns the button&#39;s associated popup menu or 0 if no popup menu has been set.
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372

◆ showMenu

void QPushButton::showMenu ( )
slot

Shows (pops up) the associated popup menu.

If there is no such menu, this function does nothing. This function does not return until the popup menu has been closed by the user.

Definition at line 578 of file qpushbutton.cpp.

Referenced by QAccessibleButton::doAction().

579 {
580  Q_D(QPushButton);
581  if (!d || !d->menu)
582  return;
583  setDown(true);
584  d->_q_popupPressed();
585 }
double d
Definition: qnumeric_p.h:62
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482

◆ sizeHint()

QSize QPushButton::sizeHint ( ) const
virtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 403 of file qpushbutton.cpp.

Referenced by QProgressDialogPrivate::layout(), minimumSizeHint(), and QCommandLinkButton::sizeHint().

404 {
405  Q_D(const QPushButton);
406  if (d->sizeHint.isValid() && d->lastAutoDefault == autoDefault())
407  return d->sizeHint;
408  d->lastAutoDefault = autoDefault();
409  ensurePolished();
410 
411  int w = 0, h = 0;
412 
413  QStyleOptionButton opt;
414  initStyleOption(&opt);
415 
416  // calculate contents size...
417 #ifndef QT_NO_ICON
418 
419  bool showButtonBoxIcons = qobject_cast<QDialogButtonBox*>(parentWidget())
421 
422  if (!icon().isNull() || showButtonBoxIcons) {
423  int ih = opt.iconSize.height();
424  int iw = opt.iconSize.width() + 4;
425  w += iw;
426  h = qMax(h, ih);
427  }
428 #endif
429  QString s(text());
430  bool empty = s.isEmpty();
431  if (empty)
432  s = QString::fromLatin1("XXXX");
433  QFontMetrics fm = fontMetrics();
434  QSize sz = fm.size(Qt::TextShowMnemonic, s);
435  if(!empty || !w)
436  w += sz.width();
437  if(!empty || !h)
438  h = qMax(h, sz.height());
439  opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height
440 #ifndef QT_NO_MENU
441  if (menu())
442  w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);
443 #endif
444  d->sizeHint = (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this).
445  expandedTo(QApplication::globalStrut()));
446  return d->sizeHint;
447 }
QSize iconSize
the size of the icon for the button
Definition: qstyleoption.h:292
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QString text() const
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
static QSize globalStrut()
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
bool autoDefault() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
int width() const
Returns the width.
Definition: qsize.h:126
QSize size(int flags, const QString &str, int tabstops=0, int *tabarray=0) const
Returns the size in pixels of text.
void initStyleOption(QStyleOptionButton *option) const
Initialize option with the values from this QPushButton.
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
QMenu * menu() const
Returns the button&#39;s associated popup menu or 0 if no popup menu has been set.
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
int height() const
Returns the height.
Definition: qsize.h:129
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QStyleOptionButton class is used to describe the parameters for drawing buttons.
Definition: qstyleoption.h:279
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
QIcon icon() const

Properties

◆ autoDefault

bool QPushButton::autoDefault
private

whether the push button is an auto default button

If this property is set to true then the push button is an auto default button.

In some GUI styles a default button is drawn with an extra frame around it, up to 3 pixels or more. Qt automatically keeps this space free around auto-default buttons, i.e. auto-default buttons may have a slightly larger size hint.

This property's default is 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.

Definition at line 61 of file qpushbutton.h.

Referenced by QMacStylePrivate::eventFilter(), QDialog::setVisible(), and QMacStylePrivate::timerEvent().

◆ default

QPushButton::default
private

whether the push button is the default button

Default and autodefault buttons decide what happens when the user presses enter in a dialog.

A button with this property set to true (i.e., the dialog's default button,) will automatically be pressed when the user presses enter, with one exception: if an autoDefault button currently has focus, the autoDefault button is pressed. When the dialog has autoDefault buttons but no default button, pressing enter will press either the autoDefault button that currently has focus, or if no button has focus, the next autoDefault button in the focus chain.

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

The default button behavior is provided only in dialogs. Buttons can always be clicked from the keyboard by pressing Spacebar when the button has focus.

If the default property is set to false on the current default button while the dialog is visible, a new default will automatically be assigned the next time a pushbutton in the dialog receives focus.

This property's default is false.

Definition at line 62 of file qpushbutton.h.

◆ flat

QPushButton::flat
private

whether the button border is raised

This property's default is false. If this property is set, most styles will not paint the button background unless the button is being pressed. setAutoFillBackground() can be used to ensure that the background is filled using the QPalette::Button brush.

Definition at line 63 of file qpushbutton.h.

Referenced by setFlat().


The documentation for this class was generated from the following files: