PDA

View Full Version : Strange QGridLayout behaviour



Mat12345
7th November 2009, 10:48
Hi!

Here is an example code with a simple QGridLayout, which contains 3 QLabels and 2 QSpinBoxes. When I increase the window's size, the two bottom rows stay at the bottom and it increases the space between them and the top QLabel.

Can someone explain why and how to obtain equally spaced rows.

I have tried using setRowStretch and it works, but then, the other Widgets which are on top of this QGridLayout in my App don't stretch at all when resizing the window.

Thanks in advance,
M.


#include <QtGui>

int main(int argc, char** argv)
{
QApplication app(argc, argv);

QWidget w;

QGridLayout* gb3fr2gridlayout=new QGridLayout;
QLabel* gb3label4=new QLabel("Number of samples :");
QLabel* gb3label5=new QLabel("Distance :");
QLabel* gb3label6=new QLabel("Time :");
QSpinBox* gb3sb1=new QSpinBox;
gb3sb1->setDisabled(true);
QSpinBox* gb3sb2=new QSpinBox;
gb3sb2->setDisabled(true);
gb3fr2gridlayout->addWidget(gb3label4, 0, 0, 1, 2);
gb3fr2gridlayout->addWidget(gb3label5, 1, 0);
gb3fr2gridlayout->addWidget(gb3label6, 2, 0);
gb3fr2gridlayout->addWidget(gb3sb1, 1, 1);
gb3fr2gridlayout->addWidget(gb3sb2, 2, 1);

w.setLayout(gb3fr2gridlayout);
w.show();

return app.exec();
}