PDA

View Full Version : QGridLayout in a QScrollArea - scrollbars do not appear



szisziszilvi
3rd August 2011, 14:30
Hi,

I have a QScrollArea on my UI and I would like to put several things into it that would be lareger than the actual size of the scrollarea. So I defined a gridlayout into it and I put just some labels for testig.

My problem is clearly to be seen on the image attached. If the size of the scrollarea is smaller than the content then the content appears compressed (slided onto each other). However I would prefer to have a fixed sized gridlayout that is in this scrollarea and the scrollbars would appear if needed.

Here is the useful code part for this:


this->gl = new QGridLayout;
this->lala = new QLabel[9]; // lala stands for "layout's label" :)
QString s;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
//setup the actual lala[]
lala[3*i + j].setText(QString::number(3*i + j));
lala[3*i + j].setFrameStyle(1);
lala[3*i + j].setLineWidth(1);
lala[3*i + j].setMinimumSize(100,100);
lala[3*i + j].setAlignment(Qt::AlignCenter);

//add lala[] to the gridlayout
gl->addWidget(&lala[3*i + j],i, j ,1,1,Qt::AlignCenter);
}
}
for(int i = 0; i < 3; i++)
{
gl->setColumnMinimumWidth(i,100); // no effect
gl->setRowMinimumHeight(i,100); // no effect
}

ui->scrollArea_2->setLayout(gl);


1. why does setColumnMinimumWidth and setRowMinimumHeight has no effect?
2. how can I achieve this: the scrollbars sould appear below minimum sizes instead of collapsing?

Or should I use a completely other solution?

Szilvi

Lykurg
3rd August 2011, 14:38
Set a widget to the scroll area, not a layout. Then it should work.

szisziszilvi
3rd August 2011, 14:53
so this is it:
this->w = new QWidget;
w->setLayout(gl);
ui->scrollArea_2->setWidget(w);