Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QAbstractButton Class

TheQAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons.More...

Header:#include <QAbstractButton>
Inherits:QWidget
Inherited By:

Q3Button,QCheckBox,QPushButton,QRadioButton, andQToolButton

Properties

Public Functions

QAbstractButton(QWidget * parent = 0)
~QAbstractButton()
boolautoExclusive() const
boolautoRepeat() const
intautoRepeatDelay() const
intautoRepeatInterval() const
QButtonGroup *group() const
QIconicon() const
QSizeiconSize() const
boolisCheckable() const
boolisChecked() const
boolisDown() const
voidsetAutoExclusive(bool)
voidsetAutoRepeat(bool)
voidsetAutoRepeatDelay(int)
voidsetAutoRepeatInterval(int)
voidsetCheckable(bool)
voidsetDown(bool)
voidsetIcon(const QIcon & icon)
voidsetShortcut(const QKeySequence & key)
voidsetText(const QString & text)
QKeySequenceshortcut() const
QStringtext() const

Public Slots

voidanimateClick(int msec = 100)
voidclick()
voidsetChecked(bool)
voidsetIconSize(const QSize & size)
voidtoggle()
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject

Signals

voidclicked(bool checked = false)
voidpressed()
voidreleased()
voidtoggled(bool checked)

Protected Functions

virtual voidcheckStateSet()
virtual boolhitButton(const QPoint & pos) const
virtual voidnextCheckState()

Reimplemented Protected Functions

virtual voidchangeEvent(QEvent * e)
virtual boolevent(QEvent * e)
virtual voidfocusInEvent(QFocusEvent * e)
virtual voidfocusOutEvent(QFocusEvent * e)
virtual voidkeyPressEvent(QKeyEvent * e)
virtual voidkeyReleaseEvent(QKeyEvent * e)
virtual voidmouseMoveEvent(QMouseEvent * e)
virtual voidmousePressEvent(QMouseEvent * e)
virtual voidmouseReleaseEvent(QMouseEvent * e)
virtual voidpaintEvent(QPaintEvent * e) = 0
virtual voidtimerEvent(QTimerEvent * e)
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Additional Inherited Members

  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject
  • 1 protected slot inherited fromQWidget

Detailed Description

TheQAbstractButton class is the abstract base class of button widgets, providing functionality common to buttons.

This class implements anabstract 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 theQRadioButton andQCheckBox classes. Push buttons are implemented in theQPushButton andQToolButton 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=newQPushButton(tr("Ro&ck && Roll"),this);

TheAlt+C shortcut is assigned to the button, i.e., when the user pressesAlt+C the button will callanimateClick(). See theQShortcut documentation for details (to display an actual ampersand, use '&&').

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

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

All of the buttons provided by Qt (QPushButton,QToolButton,QCheckBox, andQRadioButton) can display bothtext andicons.

A button can be made the default button in a dialog are provided byQPushButton::setDefault() andQPushButton::setAutoDefault().

QAbstractButton provides most of the states used for buttons:

  • isDown() indicates whether the button ispressed down.
  • isChecked() indicates whether the button ischecked. Only checkable buttons can be checked and unchecked (see below).
  • isEnabled() indicates whether the button can be pressed by the user.

    Note:As opposed to other widgets, buttons derived fromQAbstractButton accepts mouse and context menu events when disabled.

  • setAutoRepeat() sets whether the button will auto-repeat if the user holds it down.autoRepeatDelay andautoRepeatInterval define how auto-repetition is done.
  • setCheckable() sets whether the button is a toggle button or not.

The difference betweenisDown() andisChecked() is as follows. When the user clicks a toggle button to check it, the button is firstpressed then released into thechecked state. When the user clicks it again (to uncheck it), the button moves first to thepressed state, then to theunchecked state (isChecked() andisDown() 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 whenclick() oranimateClick() is called.
  4. toggled() is emitted when the state of a toggle button changes.

To subclassQAbstractButton, you must reimplement at leastpaintEvent() to draw the button's outline and its text or pixmap. It is generally advisable to reimplementsizeHint() as well, and sometimeshitButton() (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 reimplementcheckStateSet() andnextCheckState().

See alsoQButtonGroup.

Property Documentation

autoExclusive :bool

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.

Access functions:

boolautoExclusive() const
voidsetAutoExclusive(bool)

See alsoQRadioButton.

autoRepeat :bool

This property holds whether autoRepeat is enabled.

If autoRepeat is enabled, then thepressed(),released(), andclicked() 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 byautoRepeatDelay andautoRepeatInterval.

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. Thepressed(),released(), andclicked() signals will be emitted like in the normal case.

Access functions:

boolautoRepeat() const
voidsetAutoRepeat(bool)

autoRepeatDelay :int

This property holds the initial delay of auto-repetition.

IfautoRepeat is enabled, then autoRepeatDelay defines the initial delay in milliseconds before auto-repetition kicks in.

This property was introduced in Qt 4.2.

Access functions:

intautoRepeatDelay() const
voidsetAutoRepeatDelay(int)

See alsoautoRepeat andautoRepeatInterval.

autoRepeatInterval :int

This property holds the interval of auto-repetition.

IfautoRepeat is enabled, then autoRepeatInterval defines the length of the auto-repetition interval in millisecons.

This property was introduced in Qt 4.2.

Access functions:

intautoRepeatInterval() const
voidsetAutoRepeatInterval(int)

See alsoautoRepeat andautoRepeatDelay.

checkable :bool

This property holds whether the button is checkable.

By default, the button is not checkable.

Access functions:

boolisCheckable() const
voidsetCheckable(bool)

See alsochecked.

checked :bool

This property holds whether the button is checked.

Only checkable buttons can be checked. By default, the button is unchecked.

Access functions:

boolisChecked() const
voidsetChecked(bool)

Notifier signal:

voidtoggled(bool checked)

See alsocheckable.

down :bool

This property holds whether the button is pressed down.

If this property is true, the button is pressed down. The signalspressed() andclicked() are not emitted if you set this property to true. The default is false.

Access functions:

boolisDown() const
voidsetDown(bool)

icon :QIcon

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 theiconSize property.

Access functions:

QIconicon() const
voidsetIcon(const QIcon & icon)

iconSize :QSize

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.

Access functions:

QSizeiconSize() const
voidsetIconSize(const QSize & size)

shortcut :QKeySequence

This property holds the mnemonic associated with the button.

Access functions:

QKeySequenceshortcut() const
voidsetShortcut(const QKeySequence & key)

text :QString

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 theQShortcut documentation for details (to display an actual ampersand, use '&&').

There is no default text.

Access functions:

QStringtext() const
voidsetText(const QString & text)

Member Function Documentation

QAbstractButton::QAbstractButton(QWidget * parent = 0)

Constructs an abstract button with aparent.

QAbstractButton::~QAbstractButton()

Destroys the button.

[slot]void QAbstractButton::animateClick(int msec = 100)

Performs an animated click: the button is pressed immediately, and releasedmsec 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 isdisabled.

See alsoclick().

[virtual protected]void QAbstractButton::changeEvent(QEvent * e)

Reimplemented fromQWidget::changeEvent().

[virtual protected]void QAbstractButton::checkStateSet()

This virtual handler is called whensetChecked() was called, unless it was called from withinnextCheckState(). It allows subclasses to reset their intermediate button states.

See alsonextCheckState().

[slot]void QAbstractButton::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 isdisabled.

See alsoanimateClick().

[signal]void QAbstractButton::clicked(bool checked = false)

This signal is emitted when the button is activated (i.e. pressed down then released while the mouse cursor is inside the button), when the shortcut key is typed, or whenclick() oranimateClick() is called. Notably, this signal isnot emitted if you callsetDown(),setChecked() ortoggle().

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

See alsopressed(),released(), andtoggled().

[virtual protected]bool QAbstractButton::event(QEvent * e)

Reimplemented fromQObject::event().

[virtual protected]void QAbstractButton::focusInEvent(QFocusEvent * e)

Reimplemented fromQWidget::focusInEvent().

[virtual protected]void QAbstractButton::focusOutEvent(QFocusEvent * e)

Reimplemented fromQWidget::focusOutEvent().

QButtonGroup * QAbstractButton::group() const

Returns the group that this button belongs to.

If the button is not a member of anyQButtonGroup, this function returns 0.

See alsoQButtonGroup.

[virtual protected]bool QAbstractButton::hitButton(constQPoint & pos) const

Returns true ifpos 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.

[virtual protected]void QAbstractButton::keyPressEvent(QKeyEvent * e)

Reimplemented fromQWidget::keyPressEvent().

[virtual protected]void QAbstractButton::keyReleaseEvent(QKeyEvent * e)

Reimplemented fromQWidget::keyReleaseEvent().

[virtual protected]void QAbstractButton::mouseMoveEvent(QMouseEvent * e)

Reimplemented fromQWidget::mouseMoveEvent().

[virtual protected]void QAbstractButton::mousePressEvent(QMouseEvent * e)

Reimplemented fromQWidget::mousePressEvent().

[virtual protected]void QAbstractButton::mouseReleaseEvent(QMouseEvent * e)

Reimplemented fromQWidget::mouseReleaseEvent().

[virtual protected]void QAbstractButton::nextCheckState()

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

See alsocheckStateSet().

[pure virtual protected]void QAbstractButton::paintEvent(QPaintEvent * e)

Reimplemented fromQWidget::paintEvent().

[signal]void QAbstractButton::pressed()

This signal is emitted when the button is pressed down.

See alsoreleased() andclicked().

[signal]void QAbstractButton::released()

This signal is emitted when the button is released.

See alsopressed(),clicked(), andtoggled().

[virtual protected]void QAbstractButton::timerEvent(QTimerEvent * e)

Reimplemented fromQObject::timerEvent().

[slot]void QAbstractButton::toggle()

Toggles the state of a checkable button.

See alsochecked.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp