浮动/始终位于对话框上方
我在 GIMP 中注意到,当打开对话框时,它不会禁用父窗口。父窗口仍然可以使用,而子窗口浮动在其前面。 我想做同样的事情,但是对我来说,当我单击父窗口时,它会将子窗口推到后面,这样父窗口就会出现在前面。
我正在使用 Qt QDialog,但很乐意执行特定于平台的代码来使其正常工作。
我一直在这里寻找: http://msdn.microsoft.com/en- us/library/ff700543(v=vs.85).aspx
但似乎没有什么可以做我所追求的。我目前有一个狡猾的解决方案,当我的应用程序接收焦点时,我将窗口设置为 HWND_TOPMOST,然后在失去焦点时禁用此功能,但它并不理想,因为消息框被推到这些最上面的窗口后面。 IE。
SetWindowPos(winId(), stayOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOACTIVATE);
I've noticed in GIMP that when a dialog is opened it does not disable the parent window. The parent window can still be used, while the child window floats in front of it.
I want to do the same thing, how ever for me when I click on my parent window it pushes the children to the back, such that the parent comes to the front.
I'm using Qt QDialog's but happy to do platform specific code to get this working.
I've been looking here:
http://msdn.microsoft.com/en-us/library/ff700543(v=vs.85).aspx
but nothing seems to do what I'm after. I have a dodgey solution currently where I set the window to HWND_TOPMOST
when my app receives focus, then disable this when it looses focus, but its not ideal as message boxes are being pushed behind these top most windows.
ie.
SetWindowPos(winId(), stayOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOACTIVATE);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来我的对话框中没有正确设置父子关系!它需要成为父对话框/主窗口的父级,然后它才能工作。
Looks like I didnt have parenting setup correctly on my dialog! It needed to be parented to the parent dialog/main window and then it just works.
您需要调用
setWindowFlags()
包括Qt::WindowStaysOnTopHint
旗帜。You need to call
setWindowFlags()
including theQt::WindowStaysOnTopHint
flag.