1

I need to assign two shortcuts to a QAbstractButton, but I cannot find a way to do that.

It seems the only method is QAbstractButton::setShortcut(const QKeySequence & key).

Is it possible ?

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
Jérôme
  • 26,567
  • 29
  • 98
  • 120

1 Answers1

1

QAbstractButton only accept one shortcut sequence. Try to give to shortcut in QtDesigner like Alt+A & Alt+Z and you will see that you have to do Alt+A AND Alt+Z to execute shortcut. So you can not achieve to have 2 shortcuts as you want.

But there is a solution:

All QObject have a function named event that receives all events. You can create your own class that inherits from your class button (QPushButton, etc. or directly from QAbstractButton if you want to have a personalized button) with a list of QShortcutSequence (or a pair if you only want 2 shortcuts) and re-implement the event function to track the QShortcutEvent. Don't forget to release all other events to be process by parents classes.

Lukáš Lalinský
  • 40,587
  • 6
  • 104
  • 126
Patrice Bernassola
  • 14,136
  • 6
  • 46
  • 59