<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QPushButton Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QPushButton Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QPushButton widget provides a command button. <a href="#details">More...</a></p> <p>Inherits <a href="qabstractbutton.html">QAbstractButton</a>.</p><p>Inherited by <a href="qcommandlinkbutton.html">QCommandLinkButton</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qpushbutton.html#QPushButton">__init__</a></b> (<i>self</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qpushbutton.html#QPushButton-2">__init__</a></b> (<i>self</i>, QString <i>text</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qpushbutton.html#QPushButton-3">__init__</a></b> (<i>self</i>, QIcon <i>icon</i>, QString <i>text</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" />bool <b><a href="qpushbutton.html#autoDefault">autoDefault</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qpushbutton.html#event">event</a></b> (<i>self</i>, QEvent <i>e</i>)</li><li><div class="fn" /><b><a href="qpushbutton.html#focusInEvent">focusInEvent</a></b> (<i>self</i>, QFocusEvent)</li><li><div class="fn" /><b><a href="qpushbutton.html#focusOutEvent">focusOutEvent</a></b> (<i>self</i>, QFocusEvent)</li><li><div class="fn" /><b><a href="qpushbutton.html#initStyleOption">initStyleOption</a></b> (<i>self</i>, QStyleOptionButton <i>option</i>)</li><li><div class="fn" />bool <b><a href="qpushbutton.html#isDefault">isDefault</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qpushbutton.html#isFlat">isFlat</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qpushbutton.html#keyPressEvent">keyPressEvent</a></b> (<i>self</i>, QKeyEvent)</li><li><div class="fn" />QMenu <b><a href="qpushbutton.html#menu">menu</a></b> (<i>self</i>)</li><li><div class="fn" />QSize <b><a href="qpushbutton.html#minimumSizeHint">minimumSizeHint</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qpushbutton.html#paintEvent">paintEvent</a></b> (<i>self</i>, QPaintEvent)</li><li><div class="fn" /><b><a href="qpushbutton.html#setAutoDefault">setAutoDefault</a></b> (<i>self</i>, bool)</li><li><div class="fn" /><b><a href="qpushbutton.html#setDefault">setDefault</a></b> (<i>self</i>, bool)</li><li><div class="fn" /><b><a href="qpushbutton.html#setFlat">setFlat</a></b> (<i>self</i>, bool)</li><li><div class="fn" /><b><a href="qpushbutton.html#setMenu">setMenu</a></b> (<i>self</i>, QMenu <i>menu</i>)</li><li><div class="fn" /><b><a href="qpushbutton.html#showMenu">showMenu</a></b> (<i>self</i>)</li><li><div class="fn" />QSize <b><a href="qpushbutton.html#sizeHint">sizeHint</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QPushButton widget provides a command button.</p> <p>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.</p> <p>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:</p> <pre class="cpp"> <span class="type">QPushButton</span> <span class="operator">*</span>button <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QPushButton</span>(<span class="string">"&Download"</span><span class="operator">,</span> <span class="keyword">this</span>); </pre> <p>In this example the shortcut is <i>Alt+D</i>. See the <a href="qshortcut.html#mnemonic">QShortcut</a> documentation for details (to display an actual ampersand, use '&&').</p> <p>Push buttons display a textual label, and optionally a small icon. These can be set using the constructors and changed later using <a href="qabstractbutton.html#text-prop">setText</a>() and <a href="qabstractbutton.html#icon-prop">setIcon</a>(). 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".</p> <p>A push button emits the signal <a href="qabstractbutton.html#clicked">clicked</a>() 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, <a href="qabstractbutton.html#pressed">pressed</a>() and <a href="qabstractbutton.html#released">released</a>().</p> <p>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 <a href="qpushbutton.html#autoDefault-prop">setAutoDefault</a>(). 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).</p> <p>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.</p> <p>The most important modes or states are:</p> <ul> <li>Available or not (grayed out, disabled).</li> <li>Standard push button, toggling push button or menu button.</li> <li>On or off (only for toggling push buttons).</li> <li>Default or normal. The default button in a dialog can generally be "clicked" using the Enter or Return key.</li> <li>Auto-repeat or not.</li> <li>Pressed down or not.</li> </ul> <p>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) <i>and</i> 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 <a href="qfiledialog.html">QFileDialog</a>) are not command buttons, but tool buttons. Qt provides a special class (<a href="qtoolbutton.html">QToolButton</a>) for these buttons.</p> <p>If you need toggle behavior (see <a href="qabstractbutton.html#checkable-prop">setCheckable</a>()) or a button that auto-repeats the activation signal when being pushed down like the arrows in a scroll bar (see <a href="qabstractbutton.html#autoRepeat-prop">setAutoRepeat</a>()), a command button is probably not what you want. When in doubt, use a tool button.</p> <p>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 <a href="qpushbutton.html#setMenu">setMenu</a>() to associate a popup menu with a push button.</p> <p>Other classes of buttons are option buttons (see <a href="qradiobutton.html">QRadioButton</a>) and check boxes (see <a href="qcheckbox.html">QCheckBox</a>).</p> <table class="generic" width="100%"> <tr class="odd" valign="top"> <td><img alt="Screenshot of a Macintosh style push button" src="images/macintosh-pushbutton.png" /></td> <td>A push button shown in the <a href="gallery-macintosh.html">Macintosh widget style</a>. <p>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 <a href="qwidget.html#minimumSize-prop">setMinimumSize</a>() function to prevent this behavior.</p> </td> </tr> <tr class="even" valign="top"> <td><img alt="Screenshot of a Windows XP style push button" src="images/windowsxp-pushbutton.png" /></td> <td>A push button shown in the <a href="gallery-windowsxp.html">Windows XP widget style</a>.</td> </tr> <tr class="odd" valign="top"> <td><img alt="Screenshot of a Plastique style push button" src="images/plastique-pushbutton.png" /></td> <td>A push button shown in the <a href="gallery-plastique.html">Plastique widget style</a>.</td> </tr> </table> <p>In Qt, the <a href="qabstractbutton.html">QAbstractButton</a> base class provides most of the modes and other API, and QPushButton provides GUI logic. See <a href="qabstractbutton.html">QAbstractButton</a> for more information about the API.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QPushButton" />QPushButton.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a push button with no text and a <i>parent</i>.</p> <h3 class="fn"><a name="QPushButton-2" />QPushButton.__init__ (<i>self</i>, QString <i>text</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a push button with the parent <i>parent</i> and the text <i>text</i>.</p> <h3 class="fn"><a name="QPushButton-3" />QPushButton.__init__ (<i>self</i>, <a href="qicon.html">QIcon</a> <i>icon</i>, QString <i>text</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a push button with an <i>icon</i> and a <i>text</i>, and a <i>parent</i>.</p> <p>Note that you can also pass a <a href="qpixmap.html">QPixmap</a> object as an icon (thanks to the implicit type conversion provided by C++).</p> <h3 class="fn"><a name="autoDefault" />bool QPushButton.autoDefault (<i>self</i>)</h3><h3 class="fn"><a name="event" />bool QPushButton.event (<i>self</i>, <a href="qevent.html">QEvent</a> <i>e</i>)</h3><p>Reimplemented from <a href="qobject.html#event">QObject.event</a>().</p> <h3 class="fn"><a name="focusInEvent" />QPushButton.focusInEvent (<i>self</i>, <a href="qfocusevent.html">QFocusEvent</a>)</h3><p>Reimplemented from <a href="qwidget.html#focusInEvent">QWidget.focusInEvent</a>().</p> <h3 class="fn"><a name="focusOutEvent" />QPushButton.focusOutEvent (<i>self</i>, <a href="qfocusevent.html">QFocusEvent</a>)</h3><p>Reimplemented from <a href="qwidget.html#focusOutEvent">QWidget.focusOutEvent</a>().</p> <h3 class="fn"><a name="initStyleOption" />QPushButton.initStyleOption (<i>self</i>, <a href="qstyleoptionbutton.html">QStyleOptionButton</a> <i>option</i>)</h3><p>Initialize <i>option</i> with the values from this <a href="qpushbutton.html">QPushButton</a>. This method is useful for subclasses when they need a <a href="qstyleoptionbutton.html">QStyleOptionButton</a>, but don't want to fill in all the information themselves.</p> <p><b>See also</b> <a href="qstyleoption.html#initFrom">QStyleOption.initFrom</a>().</p> <h3 class="fn"><a name="isDefault" />bool QPushButton.isDefault (<i>self</i>)</h3><h3 class="fn"><a name="isFlat" />bool QPushButton.isFlat (<i>self</i>)</h3><h3 class="fn"><a name="keyPressEvent" />QPushButton.keyPressEvent (<i>self</i>, <a href="qkeyevent.html">QKeyEvent</a>)</h3><p>Reimplemented from <a href="qwidget.html#keyPressEvent">QWidget.keyPressEvent</a>().</p> <h3 class="fn"><a name="menu" /><a href="qmenu.html">QMenu</a> QPushButton.menu (<i>self</i>)</h3><p>Returns the button's associated popup menu or 0 if no popup menu has been set.</p> <p><b>See also</b> <a href="qpushbutton.html#setMenu">setMenu</a>().</p> <h3 class="fn"><a name="minimumSizeHint" /><a href="qsize.html">QSize</a> QPushButton.minimumSizeHint (<i>self</i>)</h3><p>Reimplemented from <a href="qwidget.html#minimumSizeHint-prop">QWidget.minimumSizeHint</a>().</p> <h3 class="fn"><a name="paintEvent" />QPushButton.paintEvent (<i>self</i>, <a href="qpaintevent.html">QPaintEvent</a>)</h3><p>Reimplemented from <a href="qwidget.html#paintEvent">QWidget.paintEvent</a>().</p> <h3 class="fn"><a name="setAutoDefault" />QPushButton.setAutoDefault (<i>self</i>, bool)</h3><h3 class="fn"><a name="setDefault" />QPushButton.setDefault (<i>self</i>, bool)</h3><h3 class="fn"><a name="setFlat" />QPushButton.setFlat (<i>self</i>, bool)</h3><h3 class="fn"><a name="setMenu" />QPushButton.setMenu (<i>self</i>, <a href="qmenu.html">QMenu</a> <i>menu</i>)</h3><p>Associates the popup menu <i>menu</i> 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.</p> <p>Ownership of the menu is <i>not</i> transferred to the push button.</p> <table class="generic" width="100%"> <tr class="odd" valign="top"> <td><img alt="Screenshot of a Plastique style push button with popup menu." src="images/plastique-pushbutton-menu.png" /></td> <td><img alt="Screenshot of a Cleanlooks style push button with popup menu." src="images/cleanlooks-pushbutton-menu.png" /></td> <td>Push buttons with popup menus shown in the <a href="gallery-plastique.html">Plastique widget style</a> (left) and <a href="gallery-cleanlooks.html">Cleanlooks widget style</a> (right).</td> </tr> </table> <p><b>See also</b> <a href="qpushbutton.html#menu">menu</a>().</p> <h3 class="fn"><a name="showMenu" />QPushButton.showMenu (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void showMenu()</tt>.</p><p>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.</p> <h3 class="fn"><a name="sizeHint" /><a href="qsize.html">QSize</a> QPushButton.sizeHint (<i>self</i>)</h3><p>Reimplemented from <a href="qwidget.html#sizeHint-prop">QWidget.sizeHint</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>