PDA

View Full Version : QScrollArea with QGridLayout compress items and not show V Bar



call_from
27th October 2010, 01:17
Hi.

I am trying to display many elements, derived widgets, in a frame.

When I add just a few items scrollbar looks ok.
but when adding more elements, more than real size elements are compressed and vertical scroll bar not appear.




SearchResults::SearchResults(QWidget *parent) :
QFrame(parent),
ui(new Ui::SearchResults)
{
ui->setupUi(this);

gLayout = new QGridLayout(parent);

scrollWidget = new QWidget(parent);

}





void SearchResults::setData()
{

ui->scrollArea->setBackgroundRole(QPalette::Light);

int size = K_list::instance()->DetailList.size();

gLayout->setSpacing(10);

ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);

resultWidget *rw[size];
int cont;
for(cont=0;cont<size;cont++)
{
rw[cont] = new resultWidget(this);
rw[cont]->setData( K_list::instance()->DetailList.at(cont) );
rw[cont]->connect();
gLayout->addWidget(rw[cont]);
// appear compressed
}

ui->scrollArea->setWidget(scrollWidget);

scrollWidget->setLayout(gLayout);

show();
}


Thanks for any advice

call_from
29th October 2010, 07:54
I found the solution.
Thanks God.

The problem was the UI has not set, Layout Manager and Size Policies was unset.
I choose fixed for all elements.

wysota
29th October 2010, 09:44
I don't think the problem is really there. You are doing very weird combinations with the layout - first you set it on the parent of the current widget (which should trigger a warning if the widget already has a layout) then you add widgets to it and then you set it as a layout of the child widget. Anyway, setting the "widgetResizable" property of the scroll area to true should solve the problem regardless of size policies used.