Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.gui
Class QAbstractButton

    java.lang.Object
      com.trolltech.qt.internal.QSignalEmitterInternal
          com.trolltech.qt.QSignalEmitter
              com.trolltech.qt.QtJambiObject
                  com.trolltech.qt.core.QObject
                      com.trolltech.qt.gui.QWidget
                          com.trolltech.qt.gui.QAbstractButton

All Implemented Interfaces:
  QPaintDeviceInterface, QtJambiInterface

Direct Known Subclasses:
  QCheckBox, QPushButton, QRadioButton, QToolButton

    public abstract class QAbstractButton

extends QWidget

The QAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons. This class implements an abstract button. Subclasses of this class handle user actions, and specify how the button is drawn.

QAbstractButton provides support for both push buttons and checkable (toggle) buttons. Checkable buttons are implemented in the `QRadioButton` and `QCheckBox` classes. Push buttons are implemented in the `QPushButton` and `QToolButton` classes; these also provide toggle behavior if required.

Any button can display a label containing text and an icon. `setText()` sets the text; `setIcon()` sets the icon. If a button is disabled, its label is changed to give the button a "disabled" appearance.

If the button is a text button with a string containing an ampersand ('&'), QAbstractButton automatically creates a shortcut key. For example:

            QPushButton button = new QPushButton(tr("Ro&ck && Roll"));

The Alt+C shortcut is assigned to the button, i.e., when the user presses Alt+C the button will call `animateClick()`. See the `QShortcut` documentation for details (to display an actual ampersand, use '&&').

You can also set a custom shortcut key using the `setShortcut()` function. This is useful mostly for buttons that do not have any text, because they have no automatic shortcut.

            button.setIcon(new QIcon(":/images/print.png"));
            button.setShortcut(tr("Alt+F7"));

All of the buttons provided by Qt (`QPushButton`, `QToolButton`, `QCheckBox`, and `QRadioButton`) can display both `text` and `icons`.

A button can be made the default button in a dialog are provided by `QPushButton::setDefault()` and `QPushButton::setAutoDefault()`.

QAbstractButton provides most of the states used for buttons:

- `isDown()` indicates whether the button is pressed down.
- `isChecked()` indicates whether the button is checked. Only checkable buttons can be checked and unchecked (see below).
- isEnabled() indicates whether the button can be pressed by the user.
- `setAutoRepeat()` sets whether the button will auto-repeat if the user holds it down. `autoRepeatDelay` and `autoRepeatInterval` define how auto-repetition is done.
- `setCheckable()` sets whether the button is a toggle button or not.

The difference between `isDown()` and `isChecked()` is as follows. When the user clicks a toggle button to check it, the button is first pressed then released into the checked state. When the user clicks it again (to uncheck it), the button moves first to the pressed state, then to the unchecked state (`isChecked()` and `isDown()` are both false).

QAbstractButton provides four signals:

1. `pressed()` is emitted when the left mouse button is pressed while the mouse cursor is inside the button.
2. `released()` is emitted when the left mouse button is released.
3. `clicked()` is emitted when the button is first pressed and then released, when the shortcut key is typed, or when `click()` or `animateClick()` is called.
4. `toggled()` is emitted when the state of a toggle button changes.

To subclass QAbstractButton, you must reimplement at least `paintEvent()` to draw the button's outline and its text or pixmap. It is generally advisable to reimplement sizeHint() as well, and sometimes `hitButton()` (to determine whether a button press is within the button). For buttons with more than two states (like tri-state buttons), you will also have to reimplement `checkStateSet()` and `nextCheckState()`.

See also:
  `QButtonGroup`.

Nested Class Summary

Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
`QWidget.RenderFlag, QWidget.RenderFlags`

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal`

Field Summary
`QSignalEmitter.Signal1` | `clicked` This signal takes 1 generic argument(s).
`QSignalEmitter.Signal0` | `pressed` This signal is emitted when the button is pressed down.
`QSignalEmitter.Signal0` | `released` This signal is emitted when the button is released.
`QSignalEmitter.Signal1` | `toggled` This signal takes 1 generic argument(s).

Fields inherited from class com.trolltech.qt.gui.QWidget
`customContextMenuRequested`

Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`currentSender`

Constructor Summary
`QAbstractButton()` Constructs an abstract button with a `parent`.
`QAbstractButton(QWidget parent)` Constructs an abstract button with a `parent`.

Method Summary
`void` | `animateClick()` Performs an animated click.
`void` | `animateClick(int msec)` Performs an animated click.
`boolean` | `autoExclusive()` This property holds whether auto-exclusivity is enabled.
`boolean` | `autoRepeat()` This property holds whether `autoRepeat` is enabled.
`int` | `autoRepeatDelay()` This property holds the initial delay of auto-repetition.
`int` | `autoRepeatInterval()` This property holds the interval of auto-repetition.
`protected void` | `checkStateSet()` This virtual handler is called when `setChecked()` was called, unless it was called from within `nextCheckState()`.
`void` | `click()` Performs a click.
`QButtonGroup` | `group()` Returns the group that this button belongs to.
`protected boolean` | `hitButton(QPoint pos)` Returns true if `pos` is inside the clickable button rectangle; otherwise returns false.
`QIcon` | `icon()` This property holds the icon shown on the button.
`QSize` | `iconSize()` This property holds the icon size used for this button.
`boolean` | `isCheckable()` This property holds whether the button is checkable.
`boolean` | `isChecked()` This property holds whether the button is checked.
`boolean` | `isDown()` This property holds whether the button is pressed down.
`protected void` | `nextCheckState()` This virtual handler is called when a button is clicked.
`void` | `setAutoExclusive(boolean arg__1)` This property holds whether auto-exclusivity is enabled.
`void` | `setAutoRepeat(boolean arg__1)` This property holds whether `autoRepeat` is enabled.
`void` | `setAutoRepeatDelay(int arg__1)` This property holds the initial delay of auto-repetition.
`void` | `setAutoRepeatInterval(int arg__1)` This property holds the interval of auto-repetition.
`void` | `setCheckable(boolean arg__1)` This property holds whether the button is checkable.
`void` | `setChecked(boolean arg__1)` This property holds whether the button is checked.
`void` | `setDown(boolean arg__1)` This property holds whether the button is pressed down.
`void` | `setIcon(QIcon icon)` This property holds the icon shown on the button.
`void` | `setIconSize(QSize size)` This property holds the icon size used for this button.
`void` | `setShortcut(QKeySequence.StandardKey key)` Sets the shortcut to the key sequence for the given key.
`void` | `setShortcut(QKeySequence key)` This property holds the mnemonic associated with the button.
`void` | `setShortcut(java.lang.String key)` Sets the shortcut to the key sequence for the given key string.
`void` | `setText(java.lang.String text)` This property holds the text shown on the button.
`QKeySequence` | `shortcut()` This property holds the mnemonic associated with the button.
`java.lang.String` | `text()` This property holds the text shown on the button.
`void` | `toggle()` Toggles the state of a checkable button.

Methods inherited from class com.trolltech.qt.gui.QWidget
`acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, changeEvent, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuEvent, contextMenuPolicy, cursor, depth, destroy, destroy, destroy, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, effectiveWinId, ensurePolished, enterEvent, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isMaximized, isMinimized, isModal, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyPressEvent, keyReleaseEvent, languageChange, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumSizeHint, minimumWidth, mouseDoubleClickEvent, mouseGrabber, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, move, move, moveEvent, nativeParentWidget, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, paintEngine, paintEvent, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, resizeEvent, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFilePath, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeHint, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFilePath, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y`

Methods inherited from class com.trolltech.qt.core.QObject
`childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`__qt_signalInitialization`

Methods inherited from class java.lang.Object
`clone, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Field Detail

### clicked

    public final QSignalEmitter.Signal1 clicked

  This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Boolean(named: checked)>:

  This signal is emitted when the button is activated (i. . pressed down then released while the mouse cursor is inside the button), when the shortcut key is typed, or when `click()` or `animateClick()` is called. Notably, this signal is not emitted if you call `setDown()`, `setChecked()` or `toggle()`.

  If the button is checkable, `checked` is true if the button is checked, or false if the button is unchecked.

See also:
  `pressed()` , `released()` , and `toggled()` .

### pressed

    public final QSignalEmitter.Signal0 pressed

  This signal is emitted when the button is pressed down.

See also:
  `released()` , and `clicked()` .

### released

    public final QSignalEmitter.Signal0 released

  This signal is emitted when the button is released.

See also:
  `pressed()` , `clicked()` , and `toggled()` .

### toggled

    public final QSignalEmitter.Signal1 toggled

  This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Boolean(named: checked)>:

  This signal is emitted whenever a checkable button changes its state. `checked` is true if the button is checked, or false if the button is unchecked.

  This may be the result of a user action, `click()` slot activation, or because `setChecked()` was called.

  The states of buttons in exclusive button groups are updated before this signal is emitted. This means that slots can act on either the "off" signal or the "on" signal emitted by the buttons in the group whose states have changed.

  For example, a slot that reacts to signals emitted by newly checked buttons but which ignores signals from buttons that have been unchecked can be implemented using the following pattern:

      void reactToToggle(boolean checked)
      {
         if (checked) {
            // Examine the new button states ...
         }
      }

  Button groups can be created using the `QButtonGroup` class, and updates to the button states monitored with the `QButtonGroup::buttonClicked()` signal.

See also:
  `checked`, and `clicked()` .

Constructor Detail

### QAbstractButton

    public QAbstractButton()

  Constructs an abstract button with a `parent`.

### QAbstractButton

    public QAbstractButton(QWidget parent)

  Constructs an abstract button with a `parent`.

Method Detail

### animateClick

    public final void animateClick()

  Performs an animated click. the button is pressed immediately, and released `msec` milliseconds later (the default is 100 ms).

  Calling this function again before the button was released will reset the release timer.

  All signals associated with a click are emitted as appropriate.

  This function does nothing if the button is disabled.

See also:
  `click()`.

### animateClick

    public final void animateClick(int msec)

  Performs an animated click. the button is pressed immediately, and released `msec` milliseconds later (the default is 100 ms).

  Calling this function again before the button was released will reset the release timer.

  All signals associated with a click are emitted as appropriate.

  This function does nothing if the button is disabled.

See also:
  `click()`.

### autoExclusive

    public final boolean autoExclusive()

  This property holds whether auto-exclusivity is enabled. If auto-exclusivity is enabled, checkable buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. In an exclusive button group, only one button can be checked at any time; checking another button automatically unchecks the previously checked one.

  The property has no effect on buttons that belong to a button group.

  `autoExclusive` is off by default, except for radio buttons.

See also:
  `QRadioButton`.

### autoRepeat

    public final boolean autoRepeat()

  This property holds whether `autoRepeat` is enabled. If `autoRepeat` is enabled, then the `pressed()` , `released()` , and `clicked()` signals are emitted at regular intervals when the button is down. `autoRepeat` is off by default. The initial delay and the repetition interval are defined in milliseconds by `autoRepeatDelay` and `autoRepeatInterval`.

  Note: If a button is pressed down by a shortcut key, then auto-repeat is enabled and timed by the system and not by this class. The `pressed()` , `released()` , and `clicked()` signals will be emitted like in the normal case.

### autoRepeatDelay

    public final int autoRepeatDelay()

  This property holds the initial delay of auto-repetition. If `autoRepeat` is enabled, then `autoRepeatDelay` defines the initial delay in milliseconds before auto-repetition kicks in.

See also:
  `autoRepeat`, and `autoRepeatInterval`.

### autoRepeatInterval

    public final int autoRepeatInterval()

  This property holds the interval of auto-repetition. If `autoRepeat` is enabled, then `autoRepeatInterval` defines the length of the auto-repetition interval in millisecons.

See also:
  `autoRepeat`, and `autoRepeatDelay`.

### click

    public final void click()

  Performs a click.

  All the usual signals associated with a click are emitted as appropriate. If the button is checkable, the state of the button is toggled.

  This function does nothing if the button is disabled.

See also:
  `animateClick()`.

### group

    public final QButtonGroup group()

  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`.

### icon

    public final QIcon icon()

  This property holds the icon shown on the button. The icon's default size is defined by the GUI style, but can be adjusted by setting the `iconSize` property.

### iconSize

    public final QSize iconSize()

  This property holds the icon size used for this button. The default size is defined by the GUI style. This is a maximum size for the icons. Smaller icons will not be scaled up.

### isCheckable

    public final boolean isCheckable()

  This property holds whether the button is checkable. By default, the button is not checkable.

See also:
  `checked`.

### isChecked

    public final boolean isChecked()

  This property holds whether the button is checked. Only checkable buttons can be checked. By default, the button is unchecked.

See also:
  `checkable`.

### isDown

    public final boolean isDown()

  This property holds whether the button is pressed down. If this property is true, the button is pressed down. The signals `pressed()` and `clicked()` are not emitted if you set this property to true. The default is false.

### setAutoExclusive

    public final void setAutoExclusive(boolean arg__1)

  This property holds whether auto-exclusivity is enabled. If auto-exclusivity is enabled, checkable buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. In an exclusive button group, only one button can be checked at any time; checking another button automatically unchecks the previously checked one.

  The property has no effect on buttons that belong to a button group.

  `autoExclusive` is off by default, except for radio buttons.

See also:
  `QRadioButton`.

### setAutoRepeat

    public final void setAutoRepeat(boolean arg__1)

  This property holds whether `autoRepeat` is enabled. If `autoRepeat` is enabled, then the `pressed()` , `released()` , and `clicked()` signals are emitted at regular intervals when the button is down. `autoRepeat` is off by default. The initial delay and the repetition interval are defined in milliseconds by `autoRepeatDelay` and `autoRepeatInterval`.

  Note: If a button is pressed down by a shortcut key, then auto-repeat is enabled and timed by the system and not by this class. The `pressed()` , `released()` , and `clicked()` signals will be emitted like in the normal case.

### setAutoRepeatDelay

    public final void setAutoRepeatDelay(int arg__1)

  This property holds the initial delay of auto-repetition. If `autoRepeat` is enabled, then `autoRepeatDelay` defines the initial delay in milliseconds before auto-repetition kicks in.

See also:
  `autoRepeat`, and `autoRepeatInterval`.

### setAutoRepeatInterval

    public final void setAutoRepeatInterval(int arg__1)

  This property holds the interval of auto-repetition. If `autoRepeat` is enabled, then `autoRepeatInterval` defines the length of the auto-repetition interval in millisecons.

See also:
  `autoRepeat`, and `autoRepeatDelay`.

### setCheckable

    public final void setCheckable(boolean arg__1)

  This property holds whether the button is checkable. By default, the button is not checkable.

See also:
  `checked`.

### setChecked

    public final void setChecked(boolean arg__1)

  This property holds whether the button is checked. Only checkable buttons can be checked. By default, the button is unchecked.

See also:
  `checkable`.

### setDown

    public final void setDown(boolean arg__1)

  This property holds whether the button is pressed down. If this property is true, the button is pressed down. The signals `pressed()` and `clicked()` are not emitted if you set this property to true. The default is false.

### setIcon

    public final void setIcon(QIcon icon)

  This property holds the icon shown on the button. The icon's default size is defined by the GUI style, but can be adjusted by setting the `iconSize` property.

### setIconSize

    public final void setIconSize(QSize size)

  This property holds the icon size used for this button. The default size is defined by the GUI style. This is a maximum size for the icons. Smaller icons will not be scaled up.

### setShortcut

    public final void setShortcut(QKeySequence key)

  This property holds the mnemonic associated with the button.

### setText

    public final void setText(java.lang.String text)

  This property holds the text shown on the button. If the button has no text, the `text()` function will return a an empty string.

  If the text contains an ampersand character ('&'), a shortcut is automatically created for it. The character that follows the '&' will be used as the shortcut key. Any previous shortcut will be overwritten, or cleared if no shortcut is defined by the text. See the `QShortcut` documentation for details (to display an actual ampersand, use '&&').

  There is no default text.

### shortcut

    public final QKeySequence shortcut()

  This property holds the mnemonic associated with the button.

### text

    public final java.lang.String text()

  This property holds the text shown on the button. If the button has no text, the `text()` function will return a an empty string.

  If the text contains an ampersand character ('&'), a shortcut is automatically created for it. The character that follows the '&' will be used as the shortcut key. Any previous shortcut will be overwritten, or cleared if no shortcut is defined by the text. See the `QShortcut` documentation for details (to display an actual ampersand, use '&&').

  There is no default text.

### toggle

    public final void toggle()

  Toggles the state of a checkable button.

See also:
  `checked`.

### checkStateSet

    protected void checkStateSet()

  This virtual handler is called when `setChecked()` was called, unless it was called from within `nextCheckState()`. It allows subclasses to reset their intermediate button states.

See also:
  `nextCheckState()`.

### hitButton

    protected boolean hitButton(QPoint pos)

  Returns true if `pos` is inside the clickable button rectangle; otherwise returns false.

  By default, the clickable area is the entire widget. Subclasses may reimplement this function to provide support for clickable areas of different shapes and sizes.

### nextCheckState

    protected void nextCheckState()

  This virtual handler is called when a button is clicked. The default implementation calls setChecked(!`isChecked()`) if the button `isCheckable()`. It allows subclasses to implement intermediate button states.

See also:
  `checkStateSet()`.

### setShortcut

    public final void setShortcut(java.lang.String key)

  Sets the shortcut to the key sequence for the given key string. For example "Ctrl+O" gives CTRL+'O'. The strings "Ctrl", "Shift", "Alt" and "Meta" are recognized, as well as their translated equivalents in the "QShortcut" context (using QObject::tr()). Up to four key codes may be entered by separating them with commas, e.g. "Alt+X,Ctrl+S,Q".

  Parameters:
    `key` - The description of the key sequence. Typically used with tr() so key sequences can be locale aware.

### setShortcut

    public final void setShortcut(QKeySequence.StandardKey key)

  Sets the shortcut to the key sequence for the given key. The result will depend on the currently running platform. The key sequence will be based on the first element in the list of key bindings for the key.

  Parameters:
    `key` - The key for which to select a key sequence

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD