PDA

View Full Version : QGridlayout problem



raju@123
24th September 2010, 17:12
Hi,

I am new to Qt. I am developing simple application using Qridlayout. I am not able to add the groupbox in gridlayout as sepecified position.

QGridlayout * layout = new QGridlayout()
layout->addWidget(qroupBox,2,1);
setLayout(layout);

Pbm is Qroupbox is adding in the gridlayout at posistion(0,0) not in (2,1)

can you tell me how to solve this issue?

Regards,
Raju

Lykurg
24th September 2010, 17:22
Pbm is Qroupbox is adding in the gridlayout at posistion(0,0) not in (2,1)No, that is not true! It is at (2,1) but you don't check it right. You probably look at the screen where it appears at (0,0) but that is because all other rows and columns are empty and so (2,1) acquires their space. See the output of:
QGridLayout gl;
QLabel l("foo");
gl.addWidget(&l, 2, 1);
qDebug() << "rows" << gl.rowCount();
qDebug() << "cols" << gl.columnCount();
if (gl.itemAtPosition(2, 1))
{
qDebug() << "Item at (2,1)" << gl.itemAtPosition(2, 1);
qDebug() << " -" << gl.itemAtPosition(2, 1)->widget();
}

KTvsPeacock
24th September 2010, 23:03
you could place for example empty labels on position (0,0), (0,1) and so on to solve this issue

this would look like this:


QLabel *label = new QLabel("");
QGridLayout *layout = new QGridLayout();
layout->addWidget(label,0,0,2,1);
layout->addWidget(yourGroupBox,2,1);
//add some additional label to place your groupbox at 2,1 (wherever this might be)