PDA

View Full Version : Container widget with scrollbars



a550ee
28th September 2006, 07:56
Hello!
I need to place variable amount of widgets (buttons for example) on
another widget. In case amount of childs is too much to display at
once, parent should provide scrollbars.
I use flow layout from qt examples (customlayout example) and that's
why QScrollView can't help (I don't know how it can) me. It just squeezes flow layout to one column.
I also tried simple QFrame as container. Flow layout on it works well but when all widgets can't be displayed at once it provides no scroll bars and scrapes outer layout. (see figs http://dteslenko.googlepages.com/qtinterest-1-ok.png and http://dteslenko.googlepages.com/qtinterest-1-bad.png)

wysota
28th September 2006, 07:57
How do you try to use the scrollview with flow layout?

a550ee
28th September 2006, 08:04
How do you try to use the scrollview with flow layout?
Just as it has been told in docs:


QScrollView * sv = new QScrollView( this );
QVBox * b = new QVBox(sv->viewport());
sv->addChild(b);

after it I working with b : I create layout in it and widgets with b as parent.

wysota
28th September 2006, 08:09
Maybe you should create the layout directly on the viewport without the need to use QVBox (using QWidget would be better here anyway)?

Could you provide a compilable example of the widget? I'll play with it a little to see why the outer layout doesn't work.

a550ee
28th September 2006, 08:33
Here it is! You can add more *.png files in the project directory to make problem more obvious.

wysota
28th September 2006, 08:56
Use this:

QScrollView * sv = new QScrollView( this );
QWidget * w = new QWidget(sv->viewport());
w->setPaletteBackgroundColor(Qt::white);
sv->addChild(w);
sv->setResizePolicy(QScrollView::AutoOneFit);

The magic line is the resize policy, which causes your widget to be resized to the viewport size. The result is fine, but not perfect. Something is messed up with the widget height, but I didn't want to get into the code too deep. I'm sure you'll manage to fix it. It's probably caused by heightForWidth in the layout.

a550ee
28th September 2006, 09:17
Big thanks, wysota!

anju123
15th July 2008, 10:44
Hi,
Well going forward with the similar kind of requirement,in all the reference material also I could find was a situation where there was only single widget and the scroll bar was applied to whole window, my requirement is a little different , I need scroll bar for only half of the visible area, for e.g. my window is divided in to 2 panels and I want a scroll bar only in the right hand side panel, provided the text in the panel is large. I am trying by using a widget for right hand panel and then applying QScrollArea, but no luck so far. Can anybody please help me ?

Thanks
Anju