PDA

View Full Version : Stucked on ScrollArea



Asus_G72GX
12th January 2013, 13:39
Hello have collided with QScrollArea problem. I have 5 QPushButton's on my form, what should I do if I want to place more than 5 button's on my layout, how can I use QScrollArea, so that I can scroll layout down and see other buttons. I tried to do this:
QScrollArea* scroll = new QScrollArea();
QWidget* w = new QWidget();
scroll->setWidget(w);

But scrollbar did not appeared. Please can you show how can I solve this issue. Thanks in advance

8580


Widget::Widget(QWidget *parent)
: QWidget(parent)
{


this->setFixedSize(640,360);

setAttribute(Qt::WA_LockPortraitOrientation,true);


layout=new QVBoxLayout;
btn1=new QPushButton("1");
btn2=new QPushButton("2");
btn3=new QPushButton("3");
btn4=new QPushButton("4");
btn5=new QPushButton("5");

layout->addWidget(btn1);
layout->addWidget(btn2);
layout->addWidget(btn3);
layout->addWidget(btn4);
layout->addWidget(btn5);

this->setLayout(layout);

}

wysota
12th January 2013, 13:44
Set the "widgetResizable" property in the scroll area to true.

Asus_G72GX
12th January 2013, 13:55
Thanks, for the fast respond.
But this didn't worked, Scrollbar did not appeared

QScrollArea* scroll = new QScrollArea();
scroll->setWidgetResizable(true);
QWidget* w = new QWidget();


scroll->setWidget(w);

this->setLayout(layout);

wysota
12th January 2013, 13:57
Hmmm.... Why are you setting the layout on "this" and not on "w"?

Asus_G72GX
12th January 2013, 14:03
I used this in most projects, to initialize my layout if I make this w->setLayout(layout); the layout will be empty

wysota
12th January 2013, 16:29
I don't know what you do in most of your projects, I only know you are setting the layout on the wrong widget.

freely
16th January 2013, 12:12
Hi,
I have similar problem: on custom QGraphicsView I add QGraphicsScene and put to the screen multiple custom items such that I expect my QGraphicsView scolls to see all the items, but they does not. I set ScrollBarAlwaysOn. I see scrollbars, but they doesn't updated. The same set QTreeView does update on scroll, but QGraphicsView doesn't. See video example attached:
https://www.box.com/s/mhumghw4ad3nlj5ttl83