Lahiru Chandima
Lahiru Chandima

Reputation: 24068

Block application level shortcuts in shortcut editor textbox

I need to let users change the keyboard shortcuts of some actions in my application in the preferences dialog of my application. I have subclassed QLineEdit to create a control that accepts key combinations and display the combination (eg: if user presses ctrl and I, line edit will display Ctrl + I).

If I enter the shortcut of already existing application level action in the line edit, that key press is not received by the line edit and the relevant action is triggered instead. This behavior is acceptable for me but the problem is, the behavior is not consistent with some special shortcuts such as Ctrl + C, Ctrl + A, etc. If I already have assigned such special shortcut to some action and tried to set the same shortcut for some other action, line edit does receive the event (unlike other shortcuts) and the previously assigned action doesn't get triggered.

Does anybody know a way to disable application level shortcuts so that I can receive the events in the line edit and check for duplicate shortcuts myself? Or can anybody suggest a way to consistently handle the scenario which user enters already existing shortcut to some other shortcut?

Upvotes: 0

Views: 136

Answers (1)

Jablonski
Jablonski

Reputation: 18504

You shouldn't use QLineEdit for this purpose at all. Qt has special widget to do this. It is QKeySequenceEdit. Try this widget.

http://qt-project.org/doc/qt-5/qkeysequenceedit.html

Upvotes: 3

Related Questions