开发者

Qt: chicken/egg problem with Initial Size of sub-QWidget

开发者 https://www.devze.com 2023-03-24 20:34 出处:网络
I have a *.ui definition I\'m loading and running. A certain sub-widget there has the rectangle of (x=0,y=88,w=400,h=200). When I instantia开发者_JAVA技巧te the QWidget class based on the *.ui, and sh

I have a *.ui definition I'm loading and running. A certain sub-widget there has the rectangle of (x=0,y=88,w=400,h=200). When I instantia开发者_JAVA技巧te the QWidget class based on the *.ui, and show() it, everything is fine.

I need to be able to get this rectangle BEFORE I show the widget.

When I just instantiate the class, the geometry object always returns (0,0,100,30). Only after I "show()" the widget, I'll get the correct geometry. I may be able to use the sizeHint for this sub-widget, but what about the "hint-X" or "hint-Y"? how do I get to my (x=0,y=88,w=400,h=200) BEFORE showing the widget? This is critical for one of my applications (this is a 3rd party component requirement, it cannot change).


The resize event will tell you what you need to know but there are a number of different ways to intercept it, depending on your situation.

If you are dealing with a QWidget subclass of your own, you can override resizeEvent(). If not, you can install an event filter on the object.

There are a couple of other options that are variations of these. The important parts of the documentation are The Event System and QCoreApplication::notify

0

精彩评论

暂无评论...
验证码 换一张
取 消