File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,25 +26,29 @@ class FloatQLineEdit(qw.QLineEdit):
2626 accepted_value = qc .pyqtSignal (float )
2727
2828 def __init__ (self , default = None ):
29- """Initialization.
29+ super (). __init__ ()
3030
31- Args:
32- default: Default value.
31+ validator = qg .QDoubleValidator (self )
32+ validator .setNotation (qg .QDoubleValidator .Notation .StandardNotation )
33+ validator .setLocale (qc .QLocale .c ()) # force "." as decimal separator
34+ self .setValidator (validator )
3335
34- """
35- qw .QLineEdit .__init__ (self )
36- self .setValidator (qg .QDoubleValidator ())
3736 self .setFocusPolicy (qc .Qt .FocusPolicy .ClickFocus | qc .Qt .FocusPolicy .TabFocus )
38- self .returnPressed .connect (self .do_check )
39- p = self .parent ()
40- if p :
41- self .returnPressed .connect (p .setFocus )
42- if default :
43- self .setText (str (default ))
37+
38+ self .editingFinished .connect (self .do_check )
39+
40+ if default is not None :
41+ self .setText (f"{ float (default )} " )
4442
4543 def do_check (self ):
46- text = self .text ()
47- val = float (text )
44+ text = self .text ().replace ("," , "" )
45+ try :
46+ val = float (text )
47+ except ValueError :
48+ return
49+
50+ # Normalize display (no scientific notation)
51+ self .setText (f"{ val } " )
4852 self .accepted_value .emit (val )
4953
5054
You can’t perform that action at this time.
0 commit comments