PDA

View Full Version : Qt Creator Add scrollbar in a QWidget,and change layout



mdjigo
20th June 2011, 16:03
Hi everybody,
first,excuse me for the quality of my english,i am in a french speaking country.

I have a QWidget wich contains images displayed vertically.
I want to add a scroll in the widget and change the layout if the orientation of the widget change.I mean,if the widget is Horizontal,the images must be displayed horozontally,if the widget is vertical the image should be displayed vertically.

The user can change the orientation by resizing.

i hope that i was understood.

Thank you.

Santosh Reddy
20th June 2011, 23:21
You are looking for something like a flow layout, you may need to implement you own layout manger, see this Example (http://doc.qt.nokia.com/4.7/layouts-flowlayout.html)
It should be simple enough if you understand layout basics in Qt

How is this post related to Qt Creator?

mdjigo
21st June 2011, 11:05
Thank you for your reply,
I'll try your solution.

mdjigo
21st June 2011, 13:11
I have tried your solution,it solve the problem of layout but i have not possibility to add scrollbar in my
qwidget object.

How can i add a scollbar?

Thank you again

Rachol
21st June 2011, 13:16
What about placing your widget in QScrollArea?

mdjigo
21st June 2011, 13:34
I have done this :



this->setLayout(flowLayout);
QScrollArea *scroll = new QScrollArea;
scroll->setWidget(toolbox);
scroll.show();


It display another frame,not in my actual frame

Rachol
21st June 2011, 13:40
I assume that flowLayout is your custom layout, so try this:

QHBoxLayout *mainLayout = new QHBoxLayout;
QScrollArea *area = new QScrollArea;
QWidgte *widget = new QWidget;

widget->setLayout(flowLayout);
area->setWidget(widget);
mainLayout->addWidget(area);
setLayout(mainLayout);

You also may need to set correct constraints on your flowlayout

mdjigo
21st June 2011, 14:00
I have tried your solution,but it does not work for me.