Struct rute::auto::abstract_button::AbstractButton
source · pub struct AbstractButton<'a> { /* private fields */ }
Expand description
Notice these docs are heavy WIP and not very relevent yet
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 appearance.
If the button is a text button with a string containing an ampersand (‘&’), QAbstractButton automatically creates a shortcut key. For example:
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, and therefore can’t have any automatic shortcut.
All 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 by means of 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. Note: As opposed to other widgets, buttons derived from QAbstractButton accept mouse and context menu events when disabled.
- 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:
- pressed() is emitted when the left mouse button is pressed while the mouse cursor is inside the button.
- released() is emitted when the left mouse button is released.
- 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.
- 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: ButtonGroup
Licence
The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Implementations
sourceimpl<'a> AbstractButton<'a>
impl<'a> AbstractButton<'a>
pub fn set_text(&self, text: &str) -> &Self
sourcepub fn text(&self) -> String
pub fn text(&self) -> String
If the button has no text, the text() function will return 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.
pub fn set_icon<I: IconTrait<'a>>(&self, icon: &I) -> &Self
sourcepub fn icon(&self) -> Icon<'_>
pub fn icon(&self) -> Icon<'_>
The icon’s default size is defined by the GUI style, but can be adjusted by setting the iconSize property.
The default size is defined by the GUI style. This is a maximum size for the icons. Smaller icons will not be scaled up.
sourcepub fn icon_size(&self) -> Size<'_>
pub fn icon_size(&self) -> Size<'_>
The default size is defined by the GUI style. This is a maximum size for the icons. Smaller icons will not be scaled up.
pub fn set_shortcut<K: KeySequenceTrait<'a>>(&self, key: &K) -> &Self
sourcepub fn shortcut(&self) -> KeySequence<'_>
pub fn shortcut(&self) -> KeySequence<'_>
pub fn set_checkable(&self, arg0: bool) -> &Self
pub fn is_checkable(&self) -> bool
pub fn is_checked(&self) -> bool
pub fn set_down(&self, arg0: bool) -> &Self
pub fn is_down(&self) -> bool
pub fn set_auto_repeat(&self, arg0: bool) -> &Self
sourcepub fn auto_repeat(&self) -> bool
pub fn auto_repeat(&self) -> bool
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.
If autoRepeat is enabled, then autoRepeatDelay defines the initial delay in milliseconds before auto-repetition kicks in.
See also: autoRepeat autoRepeatInterval
If autoRepeat is enabled, then autoRepeatInterval defines the length of the auto-repetition interval in millisecons.
See also: autoRepeat autoRepeatDelay
pub fn set_auto_repeat_delay(&self, arg0: i32) -> &Self
sourcepub fn auto_repeat_delay(&self) -> i32
pub fn auto_repeat_delay(&self) -> i32
If autoRepeat is enabled, then autoRepeatDelay defines the initial delay in milliseconds before auto-repetition kicks in.
See also: autoRepeat autoRepeatInterval
pub fn set_auto_repeat_interval(&self, arg0: i32) -> &Self
sourcepub fn auto_repeat_interval(&self) -> i32
pub fn auto_repeat_interval(&self) -> i32
If autoRepeat is enabled, then autoRepeatInterval defines the length of the auto-repetition interval in millisecons.
See also: autoRepeat autoRepeatDelay
pub fn set_auto_exclusive(&self, arg0: bool) -> &Self
sourcepub fn auto_exclusive(&self) -> bool
pub fn auto_exclusive(&self) -> bool
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: [RadioButton
]
sourcepub fn group(&self) -> Option<ButtonGroup<'_>>
pub fn group(&self) -> Option<ButtonGroup<'_>>
Returns the group that this button belongs to.
If the button is not a member of any QButtonGroup, this function returns 0.
See also: ButtonGroup
pub fn set_icon_size<S: SizeTrait<'a>>(&self, size: &S) -> &Self
sourcepub fn animate_click(&self, msec: i32) -> &Self
pub fn animate_click(&self, msec: i32) -> &Self
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 is released resets 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()
]
sourcepub fn click(&self) -> &Self
pub fn click(&self) -> &Self
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: [animate_click()
]
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 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()
]
[toggled()
]
sourcepub fn toggle(&self) -> &Self
pub fn toggle(&self) -> &Self
Toggles the state of a checkable button.
See also: 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() is 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 signal or the 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:
Button groups can be created using the QButtonGroup class, and updates to the button states monitored with the QButtonGroup::buttonClicked() signal.
See also: checked
[clicked()
]
pub fn set_checked(&self, arg0: bool) -> &Self
sourcepub fn set_pressed_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T) + 'a,
T: 'a,
pub fn set_pressed_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T) + 'a,
T: 'a,
This signal is emitted when the button is pressed down.
See also: [released()
]
[clicked()
]
pub fn set_pressed_event<F>(&self, func: F) -> &Selfwhere
F: Fn() + 'a,
sourcepub fn set_released_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T) + 'a,
T: 'a,
pub fn set_released_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T) + 'a,
T: 'a,
This signal is emitted when the button is released.
See also: [pressed()
]
[clicked()
]
[toggled()
]
pub fn set_released_event<F>(&self, func: F) -> &Selfwhere
F: Fn() + 'a,
sourcepub fn set_clicked_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, bool) + 'a,
T: 'a,
pub fn set_clicked_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, bool) + 'a,
T: 'a,
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 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()
]
[toggled()
]
pub fn set_clicked_event<F>(&self, func: F) -> &Selfwhere
F: Fn(bool) + 'a,
sourcepub fn set_toggled_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, bool) + 'a,
T: 'a,
pub fn set_toggled_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, bool) + 'a,
T: 'a,
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() is 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 signal or the 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:
Button groups can be created using the QButtonGroup class, and updates to the button states monitored with the QButtonGroup::buttonClicked() signal.
See also: checked
[clicked()
]
pub fn set_toggled_event<F>(&self, func: F) -> &Selfwhere
F: Fn(bool) + 'a,
sourcepub fn set_paint_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &PaintEvent<'_>) + 'a,
T: 'a,
pub fn set_paint_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &PaintEvent<'_>) + 'a,
T: 'a,
pub fn set_paint_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&PaintEvent<'_>) + 'a,
sourcepub fn set_key_press_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &KeyEvent<'_>) + 'a,
T: 'a,
pub fn set_key_press_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &KeyEvent<'_>) + 'a,
T: 'a,
pub fn set_key_press_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&KeyEvent<'_>) + 'a,
sourcepub fn set_key_release_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &KeyEvent<'_>) + 'a,
T: 'a,
pub fn set_key_release_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &KeyEvent<'_>) + 'a,
T: 'a,
pub fn set_key_release_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&KeyEvent<'_>) + 'a,
sourcepub fn set_mouse_press_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &MouseEvent<'_>) + 'a,
T: 'a,
pub fn set_mouse_press_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &MouseEvent<'_>) + 'a,
T: 'a,
pub fn set_mouse_press_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&MouseEvent<'_>) + 'a,
sourcepub fn set_mouse_release_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &MouseEvent<'_>) + 'a,
T: 'a,
pub fn set_mouse_release_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &MouseEvent<'_>) + 'a,
T: 'a,
pub fn set_mouse_release_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&MouseEvent<'_>) + 'a,
sourcepub fn set_mouse_move_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &MouseEvent<'_>) + 'a,
T: 'a,
pub fn set_mouse_move_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &MouseEvent<'_>) + 'a,
T: 'a,
pub fn set_mouse_move_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&MouseEvent<'_>) + 'a,
sourcepub fn set_focus_in_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &FocusEvent<'_>) + 'a,
T: 'a,
pub fn set_focus_in_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &FocusEvent<'_>) + 'a,
T: 'a,
pub fn set_focus_in_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&FocusEvent<'_>) + 'a,
sourcepub fn set_focus_out_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &FocusEvent<'_>) + 'a,
T: 'a,
pub fn set_focus_out_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &FocusEvent<'_>) + 'a,
T: 'a,
pub fn set_focus_out_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&FocusEvent<'_>) + 'a,
sourcepub fn set_change_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &Event<'_>) + 'a,
T: 'a,
pub fn set_change_event_ud<F, T>(&self, data: &'a T, func: F) -> &Selfwhere
F: Fn(&T, &Event<'_>) + 'a,
T: 'a,
pub fn set_change_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&Event<'_>) + 'a,
pub fn set_window_title_changed_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&str) + 'a,
pub fn set_window_icon_changed_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&Icon<'_>) + 'a,
pub fn set_window_icon_text_changed_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&str) + 'a,
pub fn set_mouse_double_click_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&MouseEvent<'_>) + 'a,
pub fn set_wheel_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&WheelEvent<'_>) + 'a,
pub fn set_enter_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&Event<'_>) + 'a,
pub fn set_leave_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&Event<'_>) + 'a,
pub fn set_move_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&MoveEvent<'_>) + 'a,
pub fn set_resize_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&ResizeEvent<'_>) + 'a,
pub fn set_close_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&CloseEvent<'_>) + 'a,
pub fn set_tablet_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&TabletEvent<'_>) + 'a,
pub fn set_drag_enter_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&DragEnterEvent<'_>) + 'a,
pub fn set_drag_move_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&DragMoveEvent<'_>) + 'a,
pub fn set_drag_leave_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&DragLeaveEvent<'_>) + 'a,
pub fn set_drop_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&DropEvent<'_>) + 'a,
pub fn set_show_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&ShowEvent<'_>) + 'a,
pub fn set_hide_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&HideEvent<'_>) + 'a,
pub fn set_custom_event<F>(&self, func: F) -> &Selfwhere
F: Fn(&Event<'_>) + 'a,
pub fn build(&self) -> Self
Trait Implementations
sourceimpl<'a> Clone for AbstractButton<'a>
impl<'a> Clone for AbstractButton<'a>
sourcefn clone(&self) -> AbstractButton<'a>
fn clone(&self) -> AbstractButton<'a>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more