简体   繁体   English

Qt /如何在不失去主窗口焦点的情况下拥有子窗口?

[英]Qt / How can I have subwindows without losing the main window focus?

I have a main window (on MS Windows) and I want to have sub windows or subpanels with free screen movement. 我有一个主窗口(在MS Windows上),并且希望有子窗口或具有自由屏幕移动功能的子面板。 I can use dialog and Qt::splashscreen flag, but when I am on these subwindows I lose the focus caption for the main window. 我可以使用对话框和Qt::splashscreen标志,但是当我在这些子窗口上时,会丢失主窗口的焦点标题。 Is there any trick to do what I want? 有什么技巧可以做我想要的吗? (Something like a multi-focus...) Maybe it is impossible? (有点像多焦点……)也许不可能吗?

I'm not sure what you mean by losing the focus. 我不确定失去焦点是什么意思。

When I create an application with multiple windows, this is what I do: in the sub-window widget, I set the parent to the main window, and set the Qt::Tool flag. 当我创建具有多个窗口的应用程序时,这就是我的工作:在子窗口小部件中,将父窗口设置为主窗口,并设置Qt :: Tool标志。 It has multiple effects: the window manager sees it as one window, and when you focus any window, all the windows raise. 它具有多种效果:窗口管理器将其视为一个窗口,并且当您聚焦任何窗口时,所有窗口都会升高。

Do you want QMdiArea ? 您想要QMdiArea吗? Or a focus proxy ? 还是焦点代理

In Qt, all top-level windows are independent, none is the "main". 在Qt中,所有顶级窗口都是独立的,没有一个是“主窗口”。 If you want to nominate one as a main window and have it steal focus from the others, then you will have to implement that manually . 如果您要提名一个作为主窗口,并让它从其他窗口中夺走焦点,那么您将必须手动实现该窗口。

Sounds like you just want to have widgets that you can move around freely on a parent widget/window, without invoking the "window focus changed" event between native Windows windows (...). 听起来您只是想拥有一个可以在父窗口小部件/窗口上自由移动的窗口小部件,而无需在本机Windows窗口之间调用“窗口焦点已更改”事件(...)。

I'm not sure if there is a ready-made solution for that, but adding some grab/move/resize events to a widget's edges shouldn't be that hard, or? 我不确定是否有现成的解决方案,但是将一些抓取/移动/调整大小事件添加到小部件的边缘应该不那么难,还是?

I'd simply catch mousedown/up events on certain areas (these should probably be widgets of their own with a link to the parent movable widget), and have them resize/move the window when the mouse moves. 我只是捕捉某些区域上的mousedown / up事件(这些事件可能是它们自己的小部件,带有指向父级可移动小部件的链接),并让它们在鼠标移动时调整大小/移动窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM