I have a QTreeWidget in which I made an addRoot function and an addChild function.
In the addRoot I want one column of the widget to be a doublespinbox and so I call it with the following code:
// Testing spinboxes
quantitySpinBox->setDecimals(1);
quantitySpinBox->setSingleStep(0.5);
ui->treeWidget->setItemWidget(itm, 7, quantitySpinBox);
connect(quantitySpinBox, SIGNAL(editingFinished()), this, SLOT(planQuantity()));
// Testing spinboxes
QDoubleSpinBox *quantitySpinBox = new QDoubleSpinBox();
quantitySpinBox->setDecimals(1);
quantitySpinBox->setSingleStep(0.5);
ui->treeWidget->setItemWidget(itm, 7, quantitySpinBox);
connect(quantitySpinBox, SIGNAL(editingFinished()), this, SLOT(planQuantity()));
To copy to clipboard, switch view to plain text mode
The spinbox appears correctly and works fine in the widget.
The problem arises when I try to access the values in the widget.
I use the following debugging code to see what the values are in the spinboxes.
qDebug() << item->data(7, Qt::DisplayRole).toFloat();
qDebug() << item->data(7, Qt::DisplayRole).toFloat();
To copy to clipboard, switch view to plain text mode
The result is all 0. Even though I change values throughout the cells it is always 0.
Is there something that I am doing wrong? How can I access the value set inside the spinbox?
Any help will be greatly appreciated because I am stuck here not going anywhere without those values.
Thanks,
Pericles
Bookmarks