PDA

View Full Version : Keyboard shortcuts problem.



Lemming
4th April 2006, 20:51
I have an action in the main menu of my application with keyboard shortuct set to "Del". It works fine, and pressing Del correctly triggers the action.

The problem is that I have one single widget in my app which should handle the "Del" press differently (actually this is a file brower, and pressing del there should delete selected files instead of performing main delete functionality of the app). Overloading the keyPressEvent for this browser and handling the del key press there doesn't give the desired result - in most cases the action is triggered, that is not right.

The deisred effect is that del pressed in the browser deletes files, and del pressed anywhere else fires the action. Btw, such behavior is shown by the textboxes, pressing del in the textbox correctly deletes the symbol under cursor instead of fiting the action.

As far as I understand, this should be somehow resolved by using event filters, but I'm not that proficient with them. Can someone help me out?

BTW, changing the action shortcut is not an option.

Thank you.

wysota
4th April 2006, 20:53
Try disabling the action when it is not valid.

Lemming
5th April 2006, 14:24
This does not help too much. Action still receives the event but doesn't trigger itself.

wysota
5th April 2006, 14:33
You can try to change the scope of one of those actions (or both) using QAction::setShortcutContext().

Lemming
5th April 2006, 17:12
Looks like I have found the solution for this problem: handling ShortcutOverride event instead of KeyPress event solves the case.

Anyway, thanks for your help.