1 #include "traderspinbox.h" 2 TraderSpinBox(QWidget * parent)3TraderSpinBox::TraderSpinBox(QWidget* parent) 4 : QDoubleSpinBox(parent) 5 { 6 installEventFilter(this); 7 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); 8 setMinimumWidth(100); 9 setSingleStep(0.01); 10 } 11 validate(QString & input,int & pos) const12QValidator::State TraderSpinBox::validate(QString& input, int& pos) const 13 { 14 if (input.indexOf('.') == -1) 15 { 16 int posComma = input.indexOf(','); 17 18 if (posComma >= 0 && input.lastIndexOf(',') == posComma) 19 input[posComma] = '.'; 20 } 21 22 return QDoubleSpinBox::validate(input, pos); 23 } 24