PDA

View Full Version : How to do that?



conexion2000
16th May 2006, 09:58
Here is sample:
http://img240.imageshack.us/img240/2239/sample8fc.png

So I would like to do something similar. As You can see there is some QGroupBox with 3 horizontal QLayouts in it. These layouts contains some widgets. And here appears my problem. How to put these layouts inside this groupbox. Setting QGroupBox as a parent doesn't seem to work, because debug functions say that QGroupBox already have a layout. When I do that in a "traditional way" (creating QLayout with QGroupBox as a parent) these widgets don't show in program.
Please help.

zlatko
16th May 2006, 10:12
It simple release with Designer !
Where is your problem ?
I attch screenshot that i release in designer and also give you code that was generated form ui file...



Form1Layout = new QGridLayout( this, 1, 1, 11, 6, "Form1Layout");

groupBox1 = new QGroupBox( this, "groupBox1" );
groupBox1->setColumnLayout(0, Qt::Vertical );
groupBox1->layout()->setSpacing( 6 );
groupBox1->layout()->setMargin( 11 );
groupBox1Layout = new QGridLayout( groupBox1->layout() );
groupBox1Layout->setAlignment( Qt::AlignTop );

layout1 = new QHBoxLayout( 0, 0, 6, "layout1");

checkBox1 = new QCheckBox( groupBox1, "checkBox1" );
layout1->addWidget( checkBox1 );

textLabel1 = new QLabel( groupBox1, "textLabel1" );
layout1->addWidget( textLabel1 );

spinBox1 = new QSpinBox( groupBox1, "spinBox1" );
layout1->addWidget( spinBox1 );

groupBox1Layout->addLayout( layout1, 0, 0 );

layout2 = new QHBoxLayout( 0, 0, 6, "layout2");

checkBox1_2 = new QCheckBox( groupBox1, "checkBox1_2" );
layout2->addWidget( checkBox1_2 );

textLabel1_2 = new QLabel( groupBox1, "textLabel1_2" );
layout2->addWidget( textLabel1_2 );

spinBox1_2 = new QSpinBox( groupBox1, "spinBox1_2" );
layout2->addWidget( spinBox1_2 );

groupBox1Layout->addLayout( layout2, 1, 0 );

layout3 = new QHBoxLayout( 0, 0, 6, "layout3");

checkBox1_3 = new QCheckBox( groupBox1, "checkBox1_3" );
layout3->addWidget( checkBox1_3 );

textLabel1_2_2 = new QLabel( groupBox1, "textLabel1_2_2" );
layout3->addWidget( textLabel1_2_2 );

spinBox1_3 = new QSpinBox( groupBox1, "spinBox1_3" );
layout3->addWidget( spinBox1_3 );

groupBox1Layout->addLayout( layout3, 2, 0 );

Form1Layout->addWidget( groupBox1, 0, 0 );

mcosta
16th May 2006, 10:14
Here is sample:
http://img240.imageshack.us/img240/2239/sample8fc.png

So I would like to do something similar. As You can see there is some QGroupBox with 3 horizontal QLayouts in it. These layouts contains some widgets. And here appears my problem. How to put these layouts inside this groupbox. Setting QGroupBox as a parent doesn't seem to work, because debug functions say that QGroupBox already have a layout. When I do that in a "traditional way" (creating QLayout with QGroupBox as a parent) these widgets don't show in program.
Please help.

You must use QWidget::setLayout.



QHBoxLayout* lay1 = new QHBoxLayout;
lay1->addWidget(wgt1_1);
...
lay1->addWidget(wgt1_N);

..........

QHBoxLayout* layN = new QHBoxLayout;
layN->addWidget(wgtN_1);
...
layN->addWidget(wgtN_N);

QVBoxLayout* v = new QVBoxLayout;
v->addLayout(lay1);
...
v->addLayout(layN);

grpBox->setLayout(v)


where wgtX_X are widget to add and grpBox are your QGroupBox.

conexion2000
16th May 2006, 15:01
Problem solved thanks to your code zlatko.