PDA

View Full Version : Problems putting layouts inside groupbox



conexion2000
16th May 2006, 08:30
Hello!
I have some code. It creates several objects and than put them in layouts. Layouts are created as a child of groupbox. But after compilation layouts with elements in it doesn't show. Only QProgressBar and QTextEdit show because they are not placed in layouts.


void GUI::createObjects()
{
kdebugf();

editBox = new QGroupBox(1,Qt::Horizontal,tr("Message Data (max 2000 chars)"),this);
spinsBox = new QGroupBox(1,Qt::Horizontal,tr("Messages Options"),this);
progressBox = new QGroupBox(1,Qt::Horizontal,tr("Progress"),this);
buttonsBox = new QGroupBox(1,Qt::Horizontal,this);


labelAmount = new QLabel(tr("Messages Amount:"), this);
labelDelay = new QLabel(tr("Messages Delay (msecs):"), this);
labelStep = new QLabel(tr("Sent message <b>0</b> from <b>0</b>"),this);

messageData = new QTextEdit(editBox);
messagesAmount = new QSpinBox(this);
messagesDelay = new QSpinBox(this);

messagesAmount->setMinValue(1);
messagesDelay->setMaxValue(9999999);
messagesAmount->setMaxValue(9999999);

progressBar = new QProgressBar(progressBox);

Cancel = new QPushButton(tr("Close"), this);
Reset = new QPushButton("Reset", this);
Go = new QPushButton(tr("Go"), this);

Go->setDefault(true);
Go->setEnabled(false);

mainLayout = new QVBoxLayout(this);
amountLayout = new QHBoxLayout;
delayLayout = new QHBoxLayout;
spinsLayout = new QVBoxLayout(spinsBox);
buttonsLayout = new QHBoxLayout(buttonsBox);

kdebugf2();
}

void GUI::layoutsInOrder()
{
kdebugf()

amountLayout->addWidget(labelAmount);
amountLayout->addWidget(messagesAmount);

delayLayout->addWidget(labelDelay);
delayLayout->addWidget(messagesDelay);

spinsLayout->addLayout(amountLayout);
spinsLayout->addLayout(delayLayout);

buttonsLayout->addWidget(Go);
buttonsLayout->addWidget(Cancel);
buttonsLayout->addWidget(Reset);

mainLayout->addWidget(editBox);
mainLayout->addWidget(spinsBox);
mainLayout->addWidget(buttonsBox);
mainLayout->addWidget(progressBox);

spinsLayout->setSpacing(10);
buttonsLayout->setSpacing(3);
mainLayout->setMargin(11);
mainLayout->setSpacing(2);

kdebugf2();
}

zlatko
16th May 2006, 08:46
IMHO you also must create PARENT layout and add to it your layouts.
Also why you create visual alements manually? It more easy create it by QDesigner and then you not be have alike this questions ;)

conexion2000
16th May 2006, 08:54
There is parent layout and it is called mainLayout. I think problem is here:
spinsLayout = new QVBoxLayout(spinsBox);
buttonsLayout = new QHBoxLayout(buttonsBox);

here I create layouts with qgroupbox as a parent. I receive warnigns that tells me that qgroupbox already has a layout. But what if I want to put some layout (with some objects in order inside it) inside a groupbox. Please help.

zlatko
16th May 2006, 09:57
There is parent layout and it is called mainLayout. I think problem is here:

actually its not main layout ;) . Under main layout i mean form layout that will be parent for your layouts. But i also think that problem ist no here.



I receive warnigns that tells me that qgroupbox already has a layout. But what if I want to put some layout (with some objects in order inside it) inside a groupbox. Please help.


Listen your warnings ;)
I think its the same if you add objects in group box without layout.
Play arround it.

conexion2000
16th May 2006, 10:01
But the problem is that I want to put some group of widgets horizontally, then these group vertically. If I do that using QGroupBox I will have 4 outlined boxes not 1.