Qt正确的方式来显示/显示/提高窗口 [英] Qt correct way to show/display/raise window
问题描述
我经常发现我需要展示一个窗口到前面。例如,当用户尝试重新加载同一个文档时,我只需调出旧的文档。为此,我有这样的代码:
Quite often I find that I need to show and bring a window to a front. For example when the user attempts to reload the same document I simply bring up the old one. To do this I have code like this:
widget->raise();
widget->activateWindow();
widget->showNormal();
它开始感觉我缺少一个快捷方式功能。当然这种类型的行为是很常见的。有没有一些首选的函数,将做所有上述和/或只是在每个目标操作系统上正确的事情?
It's starting to feel like I'm missing a shortcut function. Surely this type of behaviour is quite common. Is there some preferred function that will do all of the above and/or just do the right thing on each target OS?
注意:我刚刚注意到一个缺陷,因此一个特殊的功能是更重要的现在。如果窗口最小化, activateWindow
不起作用。即使您先将上述重新排序为 showNormal
,也会发生这种情况。
Note: I've just noticed a defect, thus a special function is even more important now. If the window is minimized, activateWindow
does not work. This happens even if you reorder the above to showNormal
first.
推荐答案
这是一个工作的捷径:
widget->setWindowState(Qt::WindowActive) ;
您可以将它与最后一个 Qt :: WindowState
的窗口。
这个符号不是很清楚。
You can couple it with the last Qt::WindowState
of the window.
This notation is not very explicit though.
这篇关于Qt正确的方式来显示/显示/提高窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!