[Qt-interest] QPushButton width problems / layout issues
John McClurkin
jwm at nei.nih.gov
Thu Jun 24 14:02:28 CEST 2010
Kustaa Nyholm wrote:
> Thanks Ramesh for taking interest.
>
>> You have two option,
>> First:
>> Set the horizontal size policy to proffered for a button which you want to
>> keep fixed.
>> Make horizontal size policy to expanding for the button to be expand.
>>
>> like this,
>>
>> QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
>> pushButton_2->setSizePolicy(sizePolicy);
>>
>
> I tried your suggestion, and it does make button 'LONG' wider, but
> button 'A' stays the same (which is too wide, previewing this in Designer
> shows a much narrower button for 'A').
>
> This is not what I need. What I want is that both buttons to take only the
> minimum amount they require and let the spacer expand to fill the space.
>
> And this is what I see in QtDesigner with identical code. As I explained I
> created a similar layout that does what I want in Designer and copy/pasted
> the code from there to my actual code and it does not work the
> same as in Designer.
>> Second:
>> You can use setgeometry() to set the position of a button.
>>
>
> Well, I did not try this, but I have understood that if there is
> a QLayout involved then setGeometry() cannot be used as the layout
> will also call setGeometry() on the widgets. But regardless the
> my point is that I do not want to create my own code to calculate
> the widget sizes and then do a setGeometry() on the widgets, because
> that is exactly what the QHBoxLayout is supposed to do. And it does,
> if I use identical code in Designer, it is only in the context
> of my application / other widgets that it fails.
>
> So I really would like to understand what can affect how the
> widgets are laid out. I've throw everything I can think of at
> the layouts and widgets in question so now I'm thinking that
> this is something (size polizy or anything) in one of the
> other widgets in the hierarchy.
>
> I've read through the QLayout.cpp but it is hard follow without
> a debugger and so far I've not been able to set break points
> with gdb on Mac OS X.
>
>
> br Kusti
>
Have you tried using QSpacerItems in the layout?
More information about the Qt-interest-old
mailing list