Created
September 25, 2020 18:57
-
-
Save max-dark/8fb20fd739dcac74bcd651a028794ac5 to your computer and use it in GitHub Desktop.
Qt5 custom QDoubleSpinBox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "numbereditor.hxx" | |
namespace Schematics::Ui::Widgets | |
{ | |
NumberEditor::NumberEditor(QWidget *parent) | |
: QDoubleSpinBox(parent) | |
{ | |
setSuffix(" mm"); | |
setDecimals(1); | |
setAlignment(Qt::AlignRight); | |
setMinimum(0.0); | |
setMaximum(1000.0); | |
} | |
QValidator::State NumberEditor::validate(QString &input, int &pos) const { | |
auto point = locale().decimalPoint(); | |
auto dot = (point == ',') ? '.' : ','; | |
// assume dot same comma | |
input.replace(dot, point); | |
return QDoubleSpinBox::validate(input, pos); | |
} | |
NumberEditor::~NumberEditor() = default; | |
} // namespace Schematics::Ui::Widgets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SCHEMATICS_NUMBEREDITOR_HXX | |
#define SCHEMATICS_NUMBEREDITOR_HXX | |
#include <QDoubleSpinBox> | |
namespace Schematics::Ui::Widgets | |
{ | |
class NumberEditor: public QDoubleSpinBox | |
{ | |
public: | |
explicit NumberEditor(QWidget *parent = nullptr); | |
~NumberEditor() override; | |
QValidator::State validate(QString &input, int &pos) const override; | |
}; | |
} // namespace Schematics::Ui::Widgets | |
#endif //SCHEMATICS_NUMBEREDITOR_HXX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment