fix: the value changed event have not triged about spinbox

This commit is contained in:
dreamsourcelabTAI 2024-04-24 14:37:48 +08:00
parent a310dcd625
commit a946081cd5

View File

@ -78,30 +78,31 @@ KeyLineEdit::KeyLineEdit(const QString &text, QWidget *parent)
void KeyLineEdit::keyPressEvent(QKeyEvent *event)
{
int key = event->key();
QString old_text = this->text();
QLineEdit::keyPressEvent(event);
if (_is_number_mode && (_min != 0 || _max != 0))
if (_is_number_mode && key >= '0' && key <= '9')
{
if (event->key() >= '0' && event->key() <= '9')
{
QString new_text = text();
QString new_text = text();
if (new_text != "")
{
int v = new_text.toInt();
int old_v = v;
if (new_text != ""){
int v = new_text.toInt();
if (_min != 0 || _max != 0){
if (v < _min ){
v = _min;
}
else if (v > _max){
v = _max;
}
}
new_text = QString::number(v);
if (v != old_v){
setText(QString::number(v));
valueChanged(v);
}
if (new_text != old_text){
setText(new_text);
valueChanged(v);
}
}
}