Container widget with scrollbars
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)
Re: Container widget with scrollbars
How do you try to use the scrollview with flow layout?
Re: Container widget with scrollbars
Quote:
Originally Posted by
wysota
How do you try to use the scrollview with flow layout?
Just as it has been told in docs:
Code:
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.
Re: Container widget with scrollbars
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.
1 Attachment(s)
Re: Container widget with scrollbars
Here it is! You can add more *.png files in the project directory to make problem more obvious.
Re: Container widget with scrollbars
Use this:
Code:
QScrollView * sv = new QScrollView( this );
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.
Re: Container widget with scrollbars
Re: Container widget with scrollbars
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