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 ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
QObjecthave a function namedeventthat receives all events. You can create your own class that inherits from your class button (QPushButton, etc. or directly fromQAbstractButtonif you want to have a personalized button) with a list ofQShortcutSequence(or a pair if you only want 2 shortcuts) and re-implement theeventfunction to track theQShortcutEvent. Don’t forget to release all other events to be process by parents classes.