PyQt4
This is regarding the precision in "QDoubleSpinBox". With out sub classing things were not working as I expected.
def __init__(self, parent=None, value=0.):
self.setRange(0., 1.)
self.setValue(0.421)
self.setSingleStep(0.001)
self.setFixedWidth(70)
self.setWrapping(True)
self.setDecimals(3)
def valueFromText(self, str):
return FixedPoint(str, 3)
def textFromValue(self, value):
print "textFromValue = ", value
return str(value)
class QxDoubleSpinBox(QtGui.QDoubleSpinBox):
def __init__(self, parent=None, value=0.):
QtGui.QDoubleSpinBox.__init__(self, parent)
self.setRange(0., 1.)
self.setValue(0.421)
self.setSingleStep(0.001)
self.setFixedWidth(70)
self.setWrapping(True)
self.setDecimals(3)
def valueFromText(self, str):
return FixedPoint(str, 3)
def textFromValue(self, value):
print "textFromValue = ", value
return str(value)
To copy to clipboard, switch view to plain text mode
As soon as I start the application, here are the results printed:
textFromValue = 0.42
textFromValue = 0.42
textFromValue = 0.42
textFromValue = 0.0
textFromValue = 1.0
textFromValue = 0.42
textFromValue = 0.42
textFromValue = 0.42
textFromValue = 0.42
textFromValue = 0.42
textFromValue = 0.0
textFromValue = 1.0
textFromValue = 0.42
textFromValue = 0.42
To copy to clipboard, switch view to plain text mode
I have no idea what's going on here and why "textFromValue" is getting called so many times with values getting changed each time. I was hoping that sub classing will solve the problem of precision.
How do I solve this?
Bookmarks