[PyQt] QDoubleSpinBox & it's precision
Prashant Saxena
animator333 at yahoo.com
Fri Oct 9 17:50:19 BST 2009
Here is the script.
#!/usr/bin/env python
from PyQt4 import QtCore, QtGui
__SINGLESTEP__ = 0.001
__DECIMALS__ = 3
__PRECISION__ = 0.001
__HSPACING__ = 5
__LABELWIDTH__ = 100
__2ndWIDGET_WIDTH__ = 70
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(__SINGLESTEP__)
self.setFixedWidth(__2ndWIDGET_WIDTH__ )
self.setWrapping(True)
self.setDecimals(__DECIMALS__)
def valueFromText(self, str):
return FixedPoint(str, 3)
def textFromValue(self, value):
print "textFromValue = ", value
#return str(FixedPoint(value, 3)) # 'FixedPoint' Custom Floating Point Management class
return str(value)
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
self.createDoubleSpinBoxes()
layout = QtGui.QHBoxLayout()
layout.addWidget(self.doubleSpinBoxesGroup)
self.setLayout(layout)
self.setWindowTitle("Spin Boxes")
def createDoubleSpinBoxes(self):
self.doubleSpinBoxesGroup = QtGui.QGroupBox("Double precision spinboxes")
self.doubleSpinBox = QxDoubleSpinBox(self, 0.421)
spinBoxLayout = QtGui.QVBoxLayout()
spinBoxLayout.addWidget(self.doubleSpinBox)
self.doubleSpinBoxesGroup.setLayout(spinBoxLayout)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
Prashant
qt-sdk-win-opensource-2009.03.1.exe
Python 2.6.3
PyQt-Py2.6-gpl-4.6-1
Win XP, 32 Bit
Add whatever you love to the Yahoo! India homepage. Try now! http://in.yahoo.com/trynew
More information about the PyQt
mailing list