Skip to content

Commit

Permalink
Rely on locale-dependent decimal separator
Browse files Browse the repository at this point in the history
  • Loading branch information
BatchDrake committed Jul 3, 2024
1 parent 1ece2a6 commit 8eb3a02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ContextAwareSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ ContextAwareSpinBox::focusOutEvent(QFocusEvent *event)

ContextAwareSpinBox::ContextAwareSpinBox(QWidget *parent) : QDoubleSpinBox(parent)
{
QLocale curLocale;

m_baseStyle = lineEdit()->style();
m_blockStyle = new BlockCursorStyle(m_baseStyle, this);

m_decimSep = curLocale.decimalPoint();
lineEdit()->setStyle(m_blockStyle);
}

Expand All @@ -94,7 +97,7 @@ ContextAwareSpinBox::decimalLength() const
int textLen = static_cast<int>(lineEdit()->text().size());

QString numberText = lineEdit()->text().mid(prefixLen, textLen - prefixLen - suffixLen);
int decPos = numberText.indexOf('.');
int decPos = numberText.indexOf(m_decimSep);

if (decPos >= 0)
return numberText.size() - decPos;
Expand Down
1 change: 1 addition & 0 deletions ContextAwareSpinBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ContextAwareSpinBox : public QDoubleSpinBox

QStyle *m_blockStyle = nullptr;
QStyle *m_baseStyle = nullptr;
QString m_decimSep = ".";
bool m_blockEnabled = false;

using QDoubleSpinBox::QDoubleSpinBox;
Expand Down

0 comments on commit 8eb3a02

Please sign in to comment.