[Interest] Qt5: Obtain current layout size
Stephen Chu
stephen at ju-ju.com
Mon Jul 23 15:41:48 CEST 2012
On 7/23/12 4:52 AM, Bo Thorsen wrote:
> Den 22-07-2012 21:49, Stephen Chu skrev:
>> On 7/22/12 6:30 AM, Bo Thorsen wrote:
>>> Den 21-07-2012 18:27, Stephen Chu skrev:
>>>> I am working on a dynamically generated form. One thing I'd like to do
>>>> is to reflow the layout into multi-column when the widgets fill the
>>>> preset window height.
>>>>
>>>> I need to find out what the current layout height is before I add the
>>>> new widget. The problem is, layout geometry is always 0x0 before the
>>>> window is shown. And if I show the window before adding the widgets,
>>>> not
>>>> only does the window flickers badly, it also doesn't auto-position
>>>> correctly. What's worse, the geometry reported is still 0x0.
>>>>
>>>> So how do I get the correct layout or parent widget size before showing
>>>> the widget/window? Thanks.
>>>
>>> You can't use size or geometry because they are properties of what is
>>> actually shown.
>>>
>>> For your case, you should use the minimum sizes instead. Those should be
>>> available to you.
>>>
>>
>> Thanks. That works. Do you happen to know how I can get the size of a
>> window maximized without first maximize it?
>
> You can't do that.
>
> The real fix for what you are trying to do here is to write your own
> layout manager class. You should subclass QLayout and implement the
> layouting yourself. It's the only way (I think) that truly does what you
> want to achieve without using a bunch of bad hacks along the way.
>
I wouldn't say it's a hack. I am arranging the layout dynamically by
considering how much the window is allowed to grow.
And even if I go custom layout route, I still need to know where I need
to place the new widget so I don't grow the window out of the screen, right?
I think I will dig into the source to see if existing QLayouts does
anything for that.
Thanks for the help.
More information about the Interest
mailing list