Frage

I was wondering if I could keep float values in a QTreeWidgetItem?

When I try to record numbers using setData(0,0,number) it rounds it up to 6 digits of precision which is not enough for me. I want to keep the exact float value for further calculations.

War es hilfreich?

Lösung

You can do one of two things, a QVariant can store any type pretty much:

v = QtCore.QVariant(aFloat)
aFloat = v.toDouble()[0]

And you would store the QVariant as the data.

Or you can set any arbitrary attributes on the item:

item = QtGui.QTreeWidgetItem()
item.foo = 123.123

Andere Tipps

Using QVariant with str can do taht I think

a = 0.12345678963582

item.setData(QtCore.Qt.UserRole,QtCore.QVariant(str(a)))

.....

val = float(item.data(QtCore.Qt.UserRole).toString()).strip())
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top