Skip to content

Instantly share code, notes, and snippets.

@nicelifeBS
Created November 10, 2014 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicelifeBS/eb6cd658e99fc3622025 to your computer and use it in GitHub Desktop.
Save nicelifeBS/eb6cd658e99fc3622025 to your computer and use it in GitHub Desktop.
PySide QDoubleSpinBox with mathematical operators
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