PDA

View Full Version : How to add space b/w column and rows of gridlayout.



Niamita
8th July 2011, 07:02
Hi
I am trying to add space b/w rows and column of gridlayout but it is not working.
I have 2*2 gridlayout like the following



QGridLayout *layout = new QGridLayout;
layout->setAlignment(Qt::AlignCenter);

layout->addWidget(button_panic, 0, 0);
layout->setHorizontalSpacing(5);
layout->addWidget(button_gas, 0, 1);
layout->setVerticalSpacing(5);
layout->addWidget(button_alarm, 2, 0);
layout->setHorizontalSpacing(5);
layout->addWidget(button_fire, 2, 1);
this->setLayout(layout);

How to add space b/w widgeta laid in layout.

Santosh Reddy
8th July 2011, 07:40
QGridLayout *layout = new QGridLayout;
layout->setAlignment(Qt::AlignCenter);

layout->addWidget(button_panic, 0, 0);
layout->addWidget(button_gas, 0, 1);
layout->addWidget(button_alarm, 1, 0); //check the row number
layout->addWidget(button_fire, 1, 1);

layout->setSpacing(50);

ChrisW67
8th July 2011, 07:41
I am assuming that "b/w" means between.

QGridLayout::setHorizontalSpacing() and QGridLayout::setVerticalSpacing(), which you are already using, set the space between adjacent widgets in the grid. You are asking for 5 pixels between rows and 5 pixels between columns. What is "not working" ?

hema
8th July 2011, 07:55
hi,

ur code is correct.its working.
may i know the error u got?