[Qt-interest] How to layout with width-for-height ?

william.crocker at analog.com william.crocker at analog.com
Sun Sep 20 15:34:37 CEST 2009


Martin:

My problems was how to layout a set of widgets
where some support height-for-width and others
only support width-for-height.

In the past I have used a multi-pass layout
algorithm and was wondering how other people
addressed the problem.

Writing a custom layout class was a given.    :-)

Bill

Martin Schröer wrote:
> First see
> http://qt.nokia.com/doc/4.5/layout.html#how-to-write-a-custom-layout-manager 
> 
> for a general overview.
> 
> The main thing is the implementation of setGeometry(const QRect &rect).
> Example:
> 
> QLayout::setGeometry(rect);
> 
> QLayoutItem *item;
> 
> foreach (item, itemList)
> 
> {
> 
>        int x = rect.x();
> 
>        int y = rect.y();
> 
>        int w = rect.width();
> 
>        int h = rect.height();
> 
> 
>       // do something, calculate coords for every item
> 
> 
>       item->setGeometry(QRect(x, y, w, h));
> 
> }
> 
> Tadaa.
> 
> Martin
> 
> william.crocker at analog.com schrieb:
>>> I was also struggling with an issue similar to yours.
>>> In short words: i gave up looking a solution that
>>> uses width-for-height and started implementing
>>> a custom layout instead.
>>>
>>>     
>>
>> The best thing you could do would be to give
>> us all a theoretical description of what you
>> did and why.
>>
>> Bill
>>
>>  
>>>> I have some widgets which can provide height-for-width.
>>>> This is supported by the Qt layout system.
>>>>
>>>> But, I also have widgets which need to behave
>>>> like width-for-height. This behavior is not supported
>>>> by the Qt layout system.
>>>>
>>>> How do I layout, given the need for some widgets
>>>> in the layout to exhibit width-for-height?
>>>>
>>>> Obviously I would like to keep it as simple as possible
>>>> and use the existing Qt widget layout classes.
>>>>
>>>> Thanks in advance.
>>>>
>>>> Bill
>>>>
>>>>       
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>   
> 



More information about the Qt-interest-old mailing list