PDA

View Full Version : QDoubleSpinBox



prashant
7th October 2009, 17:30
PyQt4

This is regarding the precision in "QDoubleSpinBox". With out sub classing things were not working as I expected.


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)


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


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?