Qt:如何强制隐藏的小部件计算其布局? [英] Qt: How to force a hidden widget to calculate its layout?

查看:481
本文介绍了Qt:如何强制隐藏的小部件计算其布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是将qwidget渲染到另一个窗口上(手动使用QPainter)

What I am trying to do is render a qwidget onto a different window (manually using a QPainter)

我有一个QWidget(w),其布局和一堆儿童控件。 w隐藏。在显示w之前,不会发生任何布局计算,这是可以预期的。

I have a QWidget (w) with a layout and a bunch of child controls. w is hidden. Until w is shown, there is no layout calculations happening, which is expected.

当我调用 w-> render(painter,w- > mapToGlobal(QPoint(0,0)),我得到了一堆彼此重叠的控件。

w-> layout() -> activate(); w-> layout()-> update()似乎没有任何作用。

When I call w->render(painter, w->mapToGlobal(QPoint(0,0)), I get a bunch of controls all overlapping each other.
w->layout()->activate();w->layout()->update() doesn't seem to do anything.

有没有一种方法可以在不显示w的情况下强制进行布局?

Is there a way to force the layout to happen without showing w?

推荐答案

在小部件上强制进行布局计算而不在其上显示屏幕上:

Forcing a layout calculation on a widget without showing it on the screen:

widget->setAttribute(Qt::WA_DontShowOnScreen);
widget->show();

show()调用将强制执行布局计算和 Qt :: WA_DontShowOnScreen 确保未显式显示窗口小部件。

The show() call will force the layout calculation, and Qt::WA_DontShowOnScreen ensures that the widget is not explicitly shown.

这篇关于Qt:如何强制隐藏的小部件计算其布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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