Web Analytics Made Easy - Statcounter
Skip to content

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

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 & mouseIcon)
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 Usage (to display nicely (Ctrl + Left mouse button) shortcut as QLabel):
    #include "SBGUIShortcutLabel.h"
    SBGUIShortcutLabel* shortcutLabel = new SBGUIShortcutLabel();
    shortcutLabel->setShortCut("Ctrl + MOUSE_LEFT_BUTTON");
    shortcutLabel->show();
    

Public Types Documentation#

enum MouseButton#

Represents mouse buttons that can be used as shortcuts.

enum SBGUIShortcutLabel::MouseButton {
    NONE = 1,
    LEFT = 2,
    CENTER = 4,
    RIGHT = 8
};


Public Functions Documentation#

function SBGUIShortcutLabel#

Constructor for SBGUIShortcutLabel .

explicit SBGUIShortcutLabel::SBGUIShortcutLabel (
    const QKeySequence & keySequence=QKeySequence(),
    QWidget * parent=nullptr
) 

Parameters:

  • keySequence The keyboard shortcut to display.
  • parent The parent widget of this label.

function setShortCut#

Sets the shortcut to be displayed on the label.

void SBGUIShortcutLabel::setShortCut (
    const QString & shortcut
) 

Parameters:

  • shortcut A string representing the shortcut, e.g., "Ctrl+C" or "Alt+D".

function toPixmap#

Converts the label's content to a QPixmap.

QPixmap SBGUIShortcutLabel::toPixmap () const

Returns:

QPixmap A pixmap representation of the label's current content.


Public Static Functions Documentation#

function getMouseShortcut#

Converts a string describing a mouse shortcut to the MouseButton enum.

static MouseButton SBGUIShortcutLabel::getMouseShortcut (
    const QString & mouseShortcut
) 

Parameters:

  • mouseShortcut A string representing the mouse button, e.g., "LEFT", "RIGHT".

Returns:

MouseButton The corresponding MouseButton enum value.


Protected Functions Documentation#

function paintEvent#

Custom paint event handler.

void SBGUIShortcutLabel::paintEvent (
    QPaintEvent * event
) override

Parameters:

  • event The paint event.

function paintMouseIcon#

Paints a mouse icon on the provided rectangle within the QPainter context.

void SBGUIShortcutLabel::paintMouseIcon (
    QPainter & painter,
    const QRect & rectExt,
    const MouseButton & mouseIcon
) 

Parameters:

  • painter QPainter context to use for drawing.
  • rectExt The rectangle where the mouse icon should be drawn.
  • mouseIcon The mouse button to draw as an icon.