shelllet / cpp-example

c++ examples
24 stars 7 forks source link

about lineEdit #2

Open stephensyn opened 4 years ago

stephensyn commented 4 years ago

问题: LineEdit通过QDataWidgetMapper绑定了数据,希望显示的数据格式保留2位小数。比如500.00 ` dataMap = new QDataWidgetMapper; //给QDataWidgetMapper加载数据源 dataMap->setModel(repair_filter_model);

dataMap->addMapping(ui->lineEdit_Amount, 11);`
shelllet commented 4 years ago

What is your ask?

stephensyn commented 4 years ago

谢谢!

stephensyn commented 4 years ago

我是这样做的。感觉好像有点LOW。还有别的方法吗? void ComplexPocess::on_lineEdit_Amount_textChanged(const QString &arg1) { ui->lineEdit_Amount->blockSignals(true); ui->lineEdit_Amount->setText(QString::number(arg1.toDouble(), 'f', 2)); ui->lineEdit_Amount->blockSignals(false); }

shelllet commented 4 years ago

LineEdit 添加验证器,或者inputMask是比较好的方式