Created
November 10, 2014 10:15
-
-
Save nicelifeBS/eb6cd658e99fc3622025 to your computer and use it in GitHub Desktop.
PySide QDoubleSpinBox with mathematical operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class superSpinBox(QDoubleSpinBox): | |
""""Spinbox which allows math expressions. Requires 'from __future__ import division' """ | |
def __init__(self, parent=None): | |
QDoubleSpinBox.__init__(self, parent) | |
def validate(self, text, pos): | |
return QValidator.Acceptable | |
def valueFromText(self, text): | |
oldValue = self.value() | |
text = unicode(text) | |
try: | |
newValue = eval(text) | |
except: | |
return oldValue | |
else: | |
return newValue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment