Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, July 2007
Carification of QSizePolicy?


Message 1 in thread

Can someone help me to understand QSizePolicy? I am using A QSplitter to
vertically lay out two widgets. I want the upper widget to expand, and the
lower widget to keep its size of 100 pixels. The user should be allowed to
resize the lower widget. Which values for the respective size policies do I
have to set to get this effect? At the moment I can only simulate something
like that by setting the stretchFactor of the upper widget to a relatively
high value. This seems a bit like a kludge.

Any ideas?

Thanks,

Arne

-- 
 [ signature omitted ] 

Message 2 in thread

On 7/30/07, Arne Schmitz <arne.schmitz@xxxxxxx> wrote:
>
> Can someone help me to understand QSizePolicy? I am using A QSplitter to
> vertically lay out two widgets. I want the upper widget to expand, and the
> lower widget to keep its size of 100 pixels. The user should be allowed to
> resize the lower widget. Which values for the respective size policies do
> I
> have to set to get this effect? At the moment I can only simulate
> something
> like that by setting the stretchFactor of the upper widget to a relatively
> high value. This seems a bit like a kludge.


You said that you want "the lower widget to keep its size of 100 pixels" and
"the user should be allowed to resize the lower widget". Which is it? For
now I'll assume you meant the user should be allowed to resize the upper
widget.

A QSplitter is used when you want two widgets to be able to share a given
area, but the user should be able to control how much of that area each
widget gets. It sounds like you want one of the widgets to have a constant
size, in which case you don't want a QSplitter. If you have a fixed-size
widget and another widget in a window, and you resize the window, then the
other widget will automatically expand/contract to compensate while the
fixed-size widget will not resize.

Tom

Message 3 in thread

Tom Panning wrote:

> You said that you want "the lower widget to keep its size of 100 pixels"
> and "the user should be allowed to resize the lower widget". Which is it?
> For now I'll assume you meant the user should be allowed to resize the
> upper widget.

No, I might have to clarify this. The lower widget should be fixed, unless
the user changes the splitter manually, you know? The upper widget is a
message log, the lower widget a textedit area. If the user wants to have
more space for editing, he can change the splitter manually. At the moment
I achieve this by setting the Stretchfactor to 40:1 between the upper and
lower widget and a minimum size of 100 px for the lower widget. This way,
the lower widget is at 100 px, except if the user manually moves the
splitter.

I hope this is clearer...

Thanks and best regards,

Arne

--
 [ signature omitted ] 

Message 4 in thread

On 7/30/07, Arne Schmitz <arne.schmitz@xxxxxxx> wrote:
>
> Tom Panning wrote:
>
> > You said that you want "the lower widget to keep its size of 100 pixels"
> > and "the user should be allowed to resize the lower widget". Which is
> it?
> > For now I'll assume you meant the user should be allowed to resize the
> > upper widget.
>
> No, I might have to clarify this. The lower widget should be fixed, unless
> the user changes the splitter manually, you know? The upper widget is a
> message log, the lower widget a textedit area. If the user wants to have
> more space for editing, he can change the splitter manually. At the moment
> I achieve this by setting the Stretchfactor to 40:1 between the upper and
> lower widget and a minimum size of 100 px for the lower widget. This way,
> the lower widget is at 100 px, except if the user manually moves the
> splitter.
>
> I hope this is clearer...


I understand now. You were almost to the correct solution. Set the upper
widget's stretch factor to 1, and set the lower widget's stretch factor to
0. Here is a small example:

#include <QApplication>
#include <QSplitter>
#include <QPushButton>

int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    QSplitter* splitter = new QSplitter;
    splitter->setOrientation(Qt::Vertical);
    QPushButton* upper = new QPushButton("Upper", splitter);
    QPushButton* lower = new QPushButton("Lower", splitter);
    const int UPPER_INDEX = 0;
    const int LOWER_INDEX = 1;
    const int NO_STRETCH = 0;
    const int STRETCHABLE = 1;
    splitter->setStretchFactor(UPPER_INDEX, STRETCHABLE);
    splitter->setStretchFactor(LOWER_INDEX, NO_STRETCH);
    splitter->show();
    return app.exec();
}

When the window is resized, only the upper button is resized, but the user
can still use the splitter handle to change the size of the lower widget.
Tom

Message 5 in thread

Tom Panning wrote:

> I understand now. You were almost to the correct solution. Set the upper
> widget's stretch factor to 1, and set the lower widget's stretch factor to
> 0. Here is a small example:

Thanks a lot!

Regards,

Arne

--
 [ signature omitted ]