3535class FloatEdit (qt .QLineEdit ):
3636 """Field to edit a float value.
3737
38+ A value can be accessed with :meth:`value` and :meth:`setValue`. Will the
39+ user do not modify the text, the original value is returned.
40+
41+ The widget supports validators from :class:`validators.CustomValidator`, which
42+ not only allow to manage float value.
43+
3844 :param parent: See :class:`QLineEdit`
3945 :param float value: The value to set the QLineEdit to.
4046 """
41- def __init__ (self , parent = None , value = None ):
47+ def __init__ (self , parent : qt . QWidget = None , value : object = None ):
4248 qt .QLineEdit .__init__ (self , parent )
4349 validator = qt .QDoubleValidator (self )
4450 self .setValidator (validator )
4551 self .setAlignment (qt .Qt .AlignRight )
52+ self .__value = None
4653 if value is not None :
4754 self .setValue (value )
4855
49- def value (self ):
56+ def keyPressEvent (self , event : qt .QEvent ):
57+ result = super (FloatEdit , self ).keyPressEvent (event )
58+ if event .isAccepted ():
59+ self .__wasModified = True
60+ return result
61+
62+ def value (self ) -> object :
5063 """Return the QLineEdit current value as a float."""
64+ if not self .isModified ():
65+ return self .__value
66+
5167 text = self .text ()
5268
5369 validator = self .validator ()
@@ -59,11 +75,12 @@ def value(self):
5975 self .setValue (value )
6076 return value
6177
62- def setValue (self , value ):
78+ def setValue (self , value : object ):
6379 """Set the current value of the LineEdit
6480
6581 :param float value: The value to set the QLineEdit to.
6682 """
83+ self .__value = value
6784 validator = self .validator ()
6885 if isinstance (validator , validators .CustomValidator ):
6986 text = validator .toText (value )
0 commit comments