Class SBGUIShortcutLabel#
ClassList > SBGUIShortcutLabel
Provides a label that can display keyboard shortcuts and mouse button icons. More...
#include <SBGUIShortcutLabel.hpp>
Inherits the following classes: QLabel, QLabel
Public Types#
| Type | Name |
|---|---|
| enum | MouseButton Represents mouse buttons that can be used as shortcuts. |
Public Functions#
| Type | Name |
|---|---|
| SBGUIShortcutLabel (const QKeySequence & keySequence=QKeySequence(), QWidget * parent=nullptr) Constructor for SBGUIShortcutLabel . |
|
| void | setShortCut (const QString & shortcut) Sets the shortcut to be displayed on the label. |
| QPixmap | toPixmap () const Converts the label's content to a QPixmap. |
Public Static Functions#
| Type | Name |
|---|---|
| MouseButton | getMouseShortcut (const QString & mouseShortcut) Converts a string describing a mouse shortcut to the MouseButton enum. |
Protected Functions#
| Type | Name |
|---|---|
| void | paintEvent (QPaintEvent * event) override Custom paint event handler. |
| void | paintMouseIcon (QPainter & painter, const QRect & rectExt, const MouseButton & mouseShortcut) Paints a mouse icon on the provided rectangle within the QPainter context. |
Detailed Description#
SBGUIShortcutLabel extends QLabel to support displaying shortcuts that include both keyboard sequences and mouse buttons. This widget is suitable for use in GUIs where indicating shortcuts to the user is necessary.
Short name: SBShortcutLabel
- Example to display nicely a shortcut (Ctrl + Left mouse button) as QLabel:
Public Types Documentation#
enum MouseButton#
Represents mouse buttons that can be used as shortcuts.
Public Functions Documentation#
function SBGUIShortcutLabel#
Constructor for SBGUIShortcutLabel .
explicit SBGUIShortcutLabel::SBGUIShortcutLabel (
const QKeySequence & keySequence=QKeySequence(),
QWidget * parent=nullptr
)
Constructs an SBGUIShortcutLabel with an optional keyboard shortcut.
The label is initialized with a fixed height and displays the provided key sequence.
Parameters:
keySequenceThe keyboard shortcut to display. Defaults to an empty QKeySequence.parentThe parent widget for the label. Defaults to nullptr.
function setShortCut#
Sets the shortcut to be displayed on the label.
Sets the shortcut string to be displayed on the label.
The provided shortcut string is processed to replace special tokens for plus and minus signs, and then set as the label's text.
Parameters:
shortcutThe shortcut string (e.g., "Ctrl+C" or "Alt+D").
function toPixmap#
Converts the label's content to a QPixmap.
Returns a pixmap representation of the label's current visual appearance.
This function creates a transparent pixmap of the label's size, renders the label onto it, and returns the resulting pixmap.
Returns:
A QPixmap containing the rendered label.
Public Static Functions Documentation#
function getMouseShortcut#
Converts a string describing a mouse shortcut to the MouseButton enum.
Converts a textual mouse shortcut description to the corresponding MouseButton enum value.
This function parses a string such as "LEFT", "RIGHT", "MOUSE_LEFT_BUTTON", or a combination of such identifiers, and returns the combined MouseButton enumeration representing the mouse buttons.
Parameters:
mouseShortcutThe textual description of the mouse shortcut (case-insensitive).
Returns:
The MouseButton enum representing the parsed mouse button(s). If the string does not match any known button, the function returns MouseButton::NONE.
Protected Functions Documentation#
function paintEvent#
Custom paint event handler.
Handles the paint event to draw the shortcut representation.
This function custom-paints the label, drawing keycaps, plus symbols, and mouse icons according to the current shortcut text.
Parameters:
eventThe paint event that triggered the repaint.
function paintMouseIcon#
Paints a mouse icon on the provided rectangle within the QPainter context.
void SBGUIShortcutLabel::paintMouseIcon (
QPainter & painter,
const QRect & rectExt,
const MouseButton & mouseShortcut
)
Paints a mouse button icon within the specified rectangle.
The function draws the mouse outline, background, and individual button indicators based on the provided mouse shortcut flags.
Parameters:
painterThe QPainter used for drawing.rectExtThe rectangle defining the area where the mouse icon should be drawn.mouseShortcutThe MouseButton flags indicating which mouse buttons are active.