Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::GlobalShortcut Class Reference

The GlobalShortcut class provides a global shortcut aka "hotkey". More...

#include <GlobalShortcut.h>

Inheritance diagram for sf::GlobalShortcut:
[legend]
Collaboration diagram for sf::GlobalShortcut:
[legend]

Public Slots

void setEnabled (bool enabled=true)
 Sets the shortcut enabled.
void setDisabled (bool disabled=true)
 Sets the shortcut disabled.

Public Member Functions

 GlobalShortcut (QObject *parent=nullptr)
 Constructs a new GlobalShortcut with parent.
 GlobalShortcut (const QKeySequence &sequence, QObject *parent=nullptr)
 Constructs a new GlobalShortcut with sequence and parent.
 ~GlobalShortcut () override
 Destructs the GlobalShortcut.
QKeySequence sequence () const
bool setSequence (const QKeySequence &sequence)
bool isEnabled () const
bool isValid () const
void setGlobal (bool global=true)
 Makes the shortcut grab a global key.
bool isGlobal () const
 Gets if the shortcut only is global.
bool autoRepeat () const
 Gets if the shortcut auto repeats.
void setAutoRepeat (bool on)
 Sets if the shortcut should auto repeat.
Q_SIGNAL void activated (GlobalShortcut *self)
 This signal is emitted when the user types the shortcut's key sequence.

Properties

bool enabled
 Gets whether the shortcut is enabled.
bool valid
 Gets whether the shortcut was successfully set up.
QKeySequence sequence
 the shortcut key sequence
bool global

Detailed Description

The GlobalShortcut class provides a global shortcut aka "hotkey".

A global shortcut triggers even if the application is not active. This makes it easy to implement applications that react to certain shortcuts still if some other application is active or if the application is for example minimized to the system tray.

Example usage:

GlobalShortcut* shortcut = new GlobalShortcut(window);
connect(shortcut, SIGNAL(activated()), window, SLOT(toggleVisibility()));
shortcut->setShortcut(QKeySequence("Ctrl+Shift+F12"));
GlobalShortcut(QObject *parent=nullptr)
Constructs a new GlobalShortcut with parent.
Q_SIGNAL void activated(GlobalShortcut *self)
This signal is emitted when the user types the shortcut's key sequence.

Constructor & Destructor Documentation

◆ GlobalShortcut() [1/2]

sf::GlobalShortcut::GlobalShortcut ( QObject * parent = nullptr)
explicit

Constructs a new GlobalShortcut with parent.

◆ GlobalShortcut() [2/2]

sf::GlobalShortcut::GlobalShortcut ( const QKeySequence & sequence,
QObject * parent = nullptr )
explicit

Constructs a new GlobalShortcut with sequence and parent.

◆ ~GlobalShortcut()

sf::GlobalShortcut::~GlobalShortcut ( )
override

Destructs the GlobalShortcut.

Member Function Documentation

◆ activated()

Q_SIGNAL void sf::GlobalShortcut::activated ( GlobalShortcut * self)

This signal is emitted when the user types the shortcut's key sequence.

See also
sequence

◆ autoRepeat()

bool sf::GlobalShortcut::autoRepeat ( ) const
nodiscard

Gets if the shortcut auto repeats.

Returns
True when auto repeating.

◆ isEnabled()

bool sf::GlobalShortcut::isEnabled ( ) const
nodiscard

◆ isGlobal()

bool sf::GlobalShortcut::isGlobal ( ) const
nodiscard

Gets if the shortcut only is global.

Returns
True when global

◆ isValid()

bool sf::GlobalShortcut::isValid ( ) const
nodiscard

◆ sequence()

QKeySequence sf::GlobalShortcut::sequence ( ) const
nodiscard

◆ setAutoRepeat()

void sf::GlobalShortcut::setAutoRepeat ( bool on)

Sets if the shortcut should auto repeat.

◆ setDisabled

void sf::GlobalShortcut::setDisabled ( bool disabled = true)
slot

Sets the shortcut disabled.

See also
enabled

◆ setEnabled

void sf::GlobalShortcut::setEnabled ( bool enabled = true)
slot

Sets the shortcut enabled.

See also
enabled

◆ setGlobal()

void sf::GlobalShortcut::setGlobal ( bool global = true)

Makes the shortcut grab a global key.

By default it is false and the shortcuts only respond when the application has focus. When the key is global the key is processed by this application and no others.

◆ setSequence()

bool sf::GlobalShortcut::setSequence ( const QKeySequence & sequence)

Property Documentation

◆ enabled

bool sf::GlobalShortcut::enabled
readwrite

Gets whether the shortcut is enabled.

A disabled shortcut does not get activated. The default value is true.

See also
setEnabled(), setDisabled()

◆ global

bool sf::GlobalShortcut::global
readwrite

◆ sequence

QKeySequence sf::GlobalShortcut::sequence
readwrite

the shortcut key sequence

sets the shortcut key sequence.

Notice that corresponding key press and release events are not delivered for registered global shortcuts even if they are disabled. Also, comma separated key sequences are not supported. Only the first part is used:

qxtShortcut->setShortcut(QKeySequence("Ctrl+Alt+A,Ctrl+Alt+B"));
Q_ASSERT(qxtShortcut->sequence() == QKeySequence("Ctrl+Alt+A"));
See also
setSequence()
sequence()

◆ valid

bool sf::GlobalShortcut::valid
read

Gets whether the shortcut was successfully set up.


The documentation for this class was generated from the following file: