summaryrefslogtreecommitdiffstats
path: root/src/gui/doc
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-09-14 11:45:24 +0200
committerIvan Solovev <ivan.solovev@qt.io>2021-09-17 09:55:11 +0200
commitfb3549fc47b19de2956cd2dda07ef67ec529cf3e (patch)
tree02beef1e21a4436f55b23f9f388e38f8f1d373a7 /src/gui/doc
parentd47278fd09f73ddc34011ab980dafc23aa453e71 (diff)
Introduce QDoubleValidator::fixup()
The provided implementation tries to fix positions for the group separator. In case of scientific notation it can also converts the value to normalized form. It uses QLocale::FloatingPointShortest internally to convert the double value back to string, so the number of decimals may change after calling this method. Change-Id: I963bc5f97b653e2bb912f4b95b09a4d1ee201e7f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/gui/doc')
-rw-r--r--src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp
index 51fc3a6e14..7503c12afb 100644
--- a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp
+++ b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp
@@ -57,6 +57,7 @@ struct Wrapper : public QWidget {
void wrapper0();
void wrapper1();
void wrapper2();
+ void wrapper3();
};
void Wrapper::wrapper0() {
@@ -164,4 +165,22 @@ s = "readm"; v.validate(s, pos); // Returns Intermediate
} // Wrapper::wrapper2
+void Wrapper::wrapper3()
+{
+//! [7]
+QString input = "0.98765e2";
+QDoubleValidator val;
+val.setLocale(QLocale::C);
+val.setNotation(QDoubleValidator::ScientificNotation);
+val.fixup(input); // input == "9.8765e+01"
+//! [7]
+//! [8]
+input = "-1234.6789";
+val.setDecimals(2);
+val.setLocale(QLocale::C);
+val.setNotation(QDoubleValidator::StandardNotation);
+val.fixup(input); // input == "-1234.68"
+//! [8]
+} // Wrapper::wrapper3
+
} // src_gui_util_qvalidator