From 07cd35ba19b5092934ac590fc1d690b5d78c22a4 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 17 Feb 2023 08:31:15 +0100 Subject: [PATCH] suppress input of group seperators - highly confusing with German locales leading to invalid inputs with unfixed final results showing a text, that does not match the actual value --- playground/gradients/main.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/playground/gradients/main.cpp b/playground/gradients/main.cpp index 5507ff74..af9d3c95 100644 --- a/playground/gradients/main.cpp +++ b/playground/gradients/main.cpp @@ -23,6 +23,23 @@ namespace { + class InputValidator : public QDoubleValidator + { + public: + InputValidator( QObject* parent = nullptr ) + : QDoubleValidator( parent ) + { + setRange( -9.99, 9.99 ); + setDecimals( 2 ); + setNotation( QDoubleValidator::StandardNotation ); + + auto locale = this->locale(); + locale.setNumberOptions( QLocale::RejectGroupSeparator ); + + setLocale( locale ); + } + }; + class NumberInput : public QskLinearBox { Q_OBJECT @@ -34,7 +51,7 @@ namespace new QskTextLabel( label, this ); m_input = new QskTextInput( this ); - m_input->setValidator( new QDoubleValidator( -9.99, 9.99, 2, m_input ) ); + m_input->setValidator( new InputValidator( m_input ) ); m_input->setText( QString::number( value ) ); const QFontMetricsF fm( m_input->font() );