PDA

View Full Version : add small space in a grid layout



uz_qt
8th November 2013, 14:01
Hi,

How can I add small variable space within a column in a grid layout?
(as in sub-bullets in MS office).

I have 5 QCheckBoxes. 3,4,5 are sub boxes of 2.

Please look at the attached picture(1pic.jpg).

spirit
8th November 2013, 14:07
Try to use QSpacerItem.

uz_qt
8th November 2013, 16:40
I tried it. But I could not achieve the desired result. Following is the sample code:



QVBoxLayout *MySubLayout = new QVBoxLayout(this);
QGroupBox *MyGroupBox = new QGroupBox(tr("Group:1"));
QGridLayout *MyGridLayout = new QGridLayout(this);

QCheckBox *Chek1 = new QCheckBox(tr("Check1")); //main checkbox1
QCheckBox *Chek2 = new QCheckBox(tr("Check2")); // main checkbox2

QCheckBox *Chek3 = new QCheckBox(tr("Check3")); //sub checkbox1
QCheckBox *Chek4 = new QCheckBox(tr("Check4")); //sub checkbox2

MyGroupBox->setLayout(MyGridLayout);

OutputLayout->addWidget(Chek1,1,0);
OutputLayout->addWidget(Chek2,2,0);
OutputLayout->addWidget(Chek3,3,0); // space required before this checkbox
OutputLayout->addWidget(Chek4,4,0); //space required before this checkbox

MySubLayout->addWidget(MyGroupBox);


Please indicate how can I add space as illustrated in the 1pic.jpg. Thanks

uz_qt
11th November 2013, 10:25
@Spirit: could u plz indicate where can I insert QSpacerItem in the above lines to get the desired result as shown in the pic?