Qt:如何在子窗口的默认系统菜单中显示 Ctrl+W 而不是 Ctrl+F4?
需要一些快速帮助,因为我可能缺少在 Qt 中帮助解决这种情况的技巧(我使用最新的 Qt 4)。
在我的 QMdiArea 中,我创建了一些子窗口。所有子窗口都附加了默认的系统菜单(最小化、最大化、留在顶部、关闭...... - 右键单击子窗口图标时可以看到)。
为了与我在应用程序主菜单中定义的内容保持一致(ctrl+w 对于关闭窗口可见),我不能接受与“关闭”相关的显示快捷方式是 Ctrl+F4。必须是 Ctrl+w。我尝试过不同的方法,包括为应用程序设置全局快捷方式(使用 setShortcutContext)...但没有运气。
Close 默认有两个快捷键:Ctrl+w 和 Ctrl+F4。我希望两者都继续工作,但应该始终显示 Ctrl+w 。
目前,我看到的唯一解决方案是替换系统菜单(QMenu)...但这对于如此简单的任务来说似乎有很多代码!
some quick help is needed, as I am probably missing the trick that would help with this situation in Qt (I use the latest Qt 4).
Within my QMdiArea, I create a few subwindows. All the subwindows have the default system menu attached (minimize, maximize, stay on top, close, ... - that's seen when right-clicking on the subwindow icon).
To be consistent with what I have defined in the main menu of my application (ctrl+w visible for closing windows), I cannot accept that the displayed shortcut related to Close is Ctrl+F4 in the subwindows' system menu. It has to be Ctrl+w. I have tried different things, including setting the shortcut global for the application (with setShortcutContext)... but no luck.
Close has by default two shortcuts: Ctrl+w and Ctrl+F4. I want both to keep working, but it's Ctrl+w which should always be displayed.
For now, the only solution I see is to replace the system menu (a QMenu)... but that seem to be a lot of code for such a simple task!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试这样设置:
请将“index”替换为合适的索引。
这对我有用。 (更新:这不起作用,CTRL+W 已经是关闭操作的指定快捷方式)
更新:
关闭操作有两个指定的快捷方式,第一个显示在菜单。如果交换顺序,则会显示 CTRL+W。
请注意,此源代码中没有平台检查;如果你在 MAC 上运行它,你会得到相反的结果,并且在 X11 中它将超出列表范围(因为只有一个快捷键:CTRL+W) 。
You can try setting it this way:
Please replace "index" with suitable index.
It worked for me. (UPDATE: this does not work, CTRL+W is already an assigned shortcut for close action)
UPDATE:
Close action has two assigned shortcuts, and the first one is displayed at menu. If you swap the order, you'll get CTRL+W displayed.
Please note that there is no platform check in this source code; if you run this on MAC you'll get the opposite result, and in X11 it will go out of list bounds (because there is only one shortcut: CTRL+W).