PDA

View Full Version : Help with QWizard



afflictedd2
11th April 2009, 16:18
Hi everyone,

This time I'm facing a new problem :\. When I register a field, in the initializePage() I cannot go back and forth again in the wizard because it will attempt to register that field again. Is it possible to unregister a field when I go back?


void ObjectsPage::initializePage()
{
layout = new QGridLayout;
QSpinBox* sbVel = NULL;
QLabel* lblVel = NULL;

QString numLayers = field("numObjs").toString();
int num = numLayers.toInt();

for (int i = 0; i < num; ++i) {
sbVel = new QSpinBox();
sbVel->setMinimum(500);
sbVel->setMaximum(20000);
sbVel->setSingleStep(500);
sbVel->setValue((i+1)*500);

lblVel = new QLabel;
lblVel->setText("Capa " + QString::number(i+1));
sbObjs.push_back(sbVel);
lblObjs.push_back(lblVel);
layout->addWidget(lblVel, i, 0);
layout->addWidget(sbVel, i, 1);
registerField("sbVel" + QString::number(i), sbObjs[i]);
}

setLayout(layout);
}

wysota
11th April 2009, 23:39
Register a field in the page constructor. initializePage() should be used to set default values to all the fields that may require initialization based on previous actions.

afflictedd2
12th April 2009, 14:20
I thought about that, but the problem is.. the number of fields I'm going to have on the next page depends on the number chosen by the user on the previous page, so I don't really know which fields I'll be registering.

wysota
14th April 2009, 21:23
In that case the field mechanism doesn't seem very appropriate for the task. It's more likely that you want a table view or something like that. If you want to keep the field approach you can query the value of each field or keep the number of fields that are already registered and simply skip registering them again. If you want less fields than before then simply hide the excessive ones.