qt:将窗口移出屏幕后,如何将其移回到默认位置,包括默认定位行为? [英] qt: after moving window off-screen, how to move it back to default position, including default positioning behaviour?

查看:773
本文介绍了qt:将窗口移出屏幕后,如何将其移回到默认位置,包括默认定位行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[qt 4.8]

要获得正确的窗口尺寸及其框架,请执行以下操作(如

To get correct window dimensions including its frame, I do the following (as described e.g. here, see comment from Daniel Hedberg).

mainWindow.move(-50000, -50000);
mainWindow.show();

// do something with the window dimensions

mainWindow.move(0, 0);
mainWindow.show()

这很好,但是,我对move(0,0)调用有问题:它使窗口总是出现在位置(0,0),而我希望具有默认行为,也就是说,应用程序仅向窗口管理器发出建议的建议,即(0,0)是放置窗口的好地方,并且WM可能会决定在必要时移动它以避免重叠.换句话说,我想切换回Qt的默认行为,好像根本没有调用move一样.

This works fine, however, I have a problem with the move(0,0) call: It makes the window always appear at position (0,0), while I would like to have the default behaviour, this is, the application only suggests to the window manager that (0,0) is a good place to position the window, and the WM might decide to shift it if necessary to avoid overlapping. In other words, I would like to switch back to Qt's default behaviour as if there weren't a call to move at all.

我该怎么做?

推荐答案

现在看一下Qt的源代码,我可以部分回答自己的问题:将对move的调用转换为定位建议,而不是请求,执行此操作:

Looking into the source code of Qt, I can now partially answer my own question: To convert a call to move into a suggestion for positioning instead of a request, do this:

mainWindow.move(100, 100);
mainWindow.setAttribute(Qt::WA_Moved, false);
mainWindow.show();

我已经使用Qt 4.8.4在X11下测试了代码,希望它也可以在其他平台上使用.

I've tested the code under X11 using Qt 4.8.4, and hopefully it works with on other platforms too.

不幸的是,这并不能解决我遇到的问题,即使用show获取屏幕外窗口的(装饰)尺寸,然后将其移至屏幕,再次调用show.似乎第一次调用show会直接设置特定于平台的窗口管理器标志,这些标志在第二次调用中不会完全重置和重新评估.实际上,我会认为这是Qt中的错误,因此我将相应地进行报告.

Unfortunately, this doesn't solve the very problem I have, namely to use show to get the (decorated) dimensions of an off-screen window which then gets moved to the screen, calling show again. It seems that the first call to show directly sets platform-specific window manager flags which aren't completely reset and reevaluated in the second call. Actually, I'm going to think that this is a bug in Qt, so I'll report it accordingly.

这篇关于qt:将窗口移出屏幕后,如何将其移回到默认位置,包括默认定位行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆