PDA

View Full Version : change layout dynamicly



stella1016
4th December 2009, 12:40
Hi,

I have problem when change the layout dynamicly.
The layout seems not be changed.

I had a look for the example already. But in my case it doesn't work. I post my code here:

One and the only one method in constructor:


void xyzWidget::create(bsDoubleMode mode, double minimum, double maximum, bool periodic, bool horizontal)
{
setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
if(horizontal)
setLayout(new QHBoxLayout(this));
else
setLayout(new QVBoxLayout(this));

layout()->setMargin(0);

w_xyzGroupBox = new QGroupBox(this);
w_xyzGroupBox->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
if(horizontal)
w_xyzGroupBox->setLayout(new QHBoxLayout(w_xyzGroupBox));
else
w_xyzGroupBox->setLayout(new QVBoxLayout(w_xyzGroupBox));
w_xyzGroupBox->hide();

w_xValue = new bsDoubleWidget(this, mode, minimum, maximum, periodic);
w_xValue->setLabel(tr("X :"));
w_xValue->setLabelColor(QColor(200, 0, 0));
connect(w_xValue, SIGNAL(valueChanged(double)), this, SLOT(xyzChanged(double)));
connect(w_xValue, SIGNAL(editingBegin()), this, SIGNAL(xyzEditingBegin()));
connect(w_xValue, SIGNAL(editingFinished()), this, SIGNAL(xyzEditingFinished()));
layout()->addWidget(w_xValue);

w_yValue = new bsDoubleWidget(this, mode, minimum, maximum, periodic);
w_yValue->setLabel(tr("Y :"));
w_yValue->setLabelColor(QColor(0, 200, 0));
connect(w_yValue, SIGNAL(valueChanged(double)), this, SLOT(xyzChanged(double)));
connect(w_yValue, SIGNAL(editingBegin()), this, SIGNAL(xyzEditingBegin()));
connect(w_yValue, SIGNAL(editingFinished()), this, SIGNAL(xyzEditingFinished()));
layout()->addWidget(w_yValue);

w_zValue = new bsDoubleWidget(this, mode, minimum, maximum, periodic);
w_zValue->setLabel(tr("Z :"));
w_zValue->setLabelColor(QColor(0, 0, 200));
connect(w_zValue, SIGNAL(valueChanged(double)), this, SLOT(xyzChanged(double)));
connect(w_zValue, SIGNAL(editingBegin()), this, SIGNAL(xyzEditingBegin()));
connect(w_zValue, SIGNAL(editingFinished()), this, SIGNAL(xyzEditingFinished()));
layout()->addWidget(w_zValue);
}


After I push a button, it is supposed to change the layout by calling this method:


void xyzWidget::setLayoutVertical()
{
layout()->removeWidget(w_xValue);
layout()->removeWidget(w_yValue);
layout()->removeWidget(w_zValue);

setLayout(new QVBoxLayout());
w_xyzGroupBox->setLayout(new QVBoxLayout(w_xyzGroupBox));

layout()->addWidget(w_xValue);
layout()->addWidget(w_yValue);
layout()->addWidget(w_zValue);
}


(The groupbox will not be used any way)

Anyone can help?

squidge
4th December 2009, 14:36
Have you looked at http://doc.trolltech.com/4.5/qstackedwidget.html ?

stella1016
4th December 2009, 17:40
Have you looked at http://doc.trolltech.com/4.5/qstackedwidget.html ?

I searched a little bit here. QStackedWidget was mentioned in several threads.
But since I don't switch back and force between two widgets, I don't see the necessarity to use QStackedWidget. You will probably ask me why not change the value during initialization. I just need this switch one time.