fix: the text input maybe can only input a number

This commit is contained in:
dreamsourcelabTAI 2024-04-23 10:48:22 +08:00
parent e8eee13db6
commit e2e6bbaee1
3 changed files with 24 additions and 14 deletions

View File

@ -168,12 +168,6 @@ PopupLineEdit::PopupLineEdit(const QString &text, QWidget *parent)
_is_number_mode = false;
}
PopupLineEdit::PopupLineEdit(bool isNumberMode, QWidget *parent)
:QLineEdit(parent)
{
_is_number_mode = isNumberMode;
}
void PopupLineEdit::mousePressEvent(QMouseEvent *event)
{
showPupopInput();
@ -190,11 +184,6 @@ void PopupLineEdit::showPupopInput()
input->GetInput()->setInputMask(mask);
}
auto regular = this->validator();
if (regular != NULL){
input->GetInput()->setValidator(regular);
}
input->GetInput()->setMaxLength(this->maxLength());
input->GetInput()->setText(this->text());
input->setFont(this->font());
@ -203,6 +192,12 @@ void PopupLineEdit::showPupopInput()
QIntValidator *validator = new QIntValidator();
input->GetInput()->setValidator(validator);
}
else{
auto regular = this->validator();
if (regular != NULL){
input->GetInput()->setValidator(regular);
}
}
_old_text = this->text();
@ -222,6 +217,19 @@ void PopupLineEdit::onPopupInputEditEnd(QString text)
}
}
bool PopupLineEdit::set_number_mode(bool isNumberMode)
{
_is_number_mode = isNumberMode;
if (_is_number_mode){
QIntValidator *validator = new QIntValidator();
setValidator(validator);
}
else{
setValidator(NULL);
}
}
int PopupLineEdit::value()
{
assert(_is_number_mode);

View File

@ -89,13 +89,14 @@ class PopupLineEdit : public QLineEdit
public:
explicit PopupLineEdit(QWidget *parent = nullptr);
explicit PopupLineEdit(const QString &, QWidget *parent = nullptr);
explicit PopupLineEdit(bool isNumberMode, QWidget *parent = nullptr);
explicit PopupLineEdit(const QString &text, QWidget *parent = nullptr);
inline bool is_number_mode(){
return _is_number_mode;
}
bool set_number_mode(bool isNumberMode);
int value();
void setValue(int value);

View File

@ -588,7 +588,8 @@ void TriggerDock::setup_adv_tab()
_value0_lineEdit->setInputMask(mask);
_value0_lineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
_value0_lineEdit_list.push_back(_value0_lineEdit);
PopupLineEdit *_count_spinBox = new PopupLineEdit(true, _stage_tabWidget);
PopupLineEdit *_count_spinBox = new PopupLineEdit(_stage_tabWidget);
_count_spinBox->set_number_mode(true);
// _count_spinBox->setRange(1, INT32_MAX);
//_count_spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
_count_spinBox_list.push_back(_count_spinBox);