开发者

How to avoid Qt shortcut ambiguity (especially when the shortcuts have different contexts)?

I have an app that has Ctrl+S as a shortcut for the Save action in the file menu. This action has the default shortcut context of Qt::WindowShortcut.

In this app there's a docking window with an action that also uses the shortcut Ctrl+S. This shortcut has the context Qt::WidgetShortcut.

The window shortcut works fine. (It is executed if Ctrl+S is pressed when the focus is anywhere except the docking window I mentioned.)

The widget shortcut doesn't really work. That is, if the window action is disabled, then the widget one works, since there's no ambiguity. But if both actions are enabled, and the focus is on the docking window, then Ctrl+S does nothing.

It would seem to me that it wouldn't be unreasonable to开发者_如何转开发 expect that in the case of identical active shortcuts, then if one has more "local" context than the other, it would be the one to execute. I don't suppose there's any way to tell the Qt framework that that's what I want to happen? Or a general way to work around this? I could simply change one of the shortcuts so they aren't ambiguous, but these are localizable and platform-dependent so I can't guarantee that no other similar situation will arise.


I had a similar situation where two widgets had the same shortcut (for two different actions), but only one was being called. The only way I was able to fix this was to 1. remove the shortcuts from the actions in the two widgets 2. create another action with the shortcut in the parent window 3. call the appropriate widget handler from the window handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜