Created
January 7, 2013 09:24
-
-
Save jirivrany/4473639 to your computer and use it in GitHub Desktop.
QDoubleValidator seems to ignore range settings. This seems to be a working solution. Original here: http://learnwithhelvin.blogspot.cz/2010/01/qdoublevalidator.html
This file contains 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
from PyQt4.QtGui import QDoubleValidator, QValidator | |
from sys import float_info | |
class MyDoubleValidator(QDoubleValidator): | |
''' | |
Fix for strange behavior of default QDoubleValidator | |
''' | |
def __init__(self, bottom = float_info.min, \ | |
top = float_info.max, \ | |
decimals = float_info.dig, parent = None): | |
super(MyDoubleValidator, self).__init__(bottom, top, decimals, parent) | |
def validate(self, input_value, pos): | |
state, pos = QDoubleValidator.validate(self, input_value, pos) | |
if input_value.isEmpty() or input_value == '.': | |
return QValidator.Intermediate, pos | |
if state != QValidator.Acceptable: | |
return QValidator.Invalid, pos | |
return QValidator.Acceptable, pos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment