I changed the widget to a QDoubleSpinBox which makes it easier to handle the values since I only want decimals at 0.5 steps.
quantitySpinBox->setDecimals(1);
quantitySpinBox->setSingleStep(0.5);
ui->treeWidget->setItemWidget(itm, 7, quantitySpinBox);
connect(quantitySpinBox, SIGNAL(valueChanged(double)), this, SLOT(planQuantity()));
QDoubleSpinBox *quantitySpinBox = new QDoubleSpinBox();
quantitySpinBox->setDecimals(1);
quantitySpinBox->setSingleStep(0.5);
ui->treeWidget->setItemWidget(itm, 7, quantitySpinBox);
connect(quantitySpinBox, SIGNAL(valueChanged(double)), this, SLOT(planQuantity()));
To copy to clipboard, switch view to plain text mode
But again when I try to access the value with the following code it does not return anything.
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
{
qDebug() << item->data(7, Qt::DisplayRole).toFloat();
quantity += item->text(7).toFloat();
}
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
{
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
qDebug() << item->data(7, Qt::DisplayRole).toFloat();
quantity += item->text(7).toFloat();
}
To copy to clipboard, switch view to plain text mode
Any ideas on how to access a value in a widget within the QTreeWidgetItem?
Thanks,
Pericles
Bookmarks