1

I am using a QTableWidget to input values for a user-defined tool's parameters. Each parameter has a maximum size limit in bytes.

I used QIntValidator with QLineEdit and setCellWidget. It's working fine up to 4 bytes signed integers, while not taking entry when set for 4 bytes unsigned integer.

  QLineEdit *edit = new QLineEdit(ui->tableWidget);
  edit->setValidator(new QIntValidator(tpMinValue.at(i).toUInt(), tpMaxValue.at(i).toUInt(), edit));
  edit->setStyleSheet("QLineEdit { border: none }");
  ui->tableWidget->setCellWidget((i-1), 2, edit);

Examples

  1. tool A: max size is 2 bytes (65,535) unsigned integer; I am able to enter values up to 65,535 in the cell.

  2. tool B: max size is 4 bytes (2,147,483,647) signed integer; I am able to enter values up to 2,147,483,647 in the cell.

  3. tool C: max size is 4 bytes (4,294,967,295) unsigned integer; I am unable to enter any value in the cell.

It is not allowing me to enter any number in the cell, since the max allowed value of QIntValidator is (2,147,483,647) signed integer.

Is there an alternative way to overcome the issue?

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
skg
  • 948
  • 2
  • 19
  • 35

1 Answers1

2

This is because QIntValidtor works with int which is a signed integer. Someone else had a similar problem with QSpinbox and had to extend its functionality to work this out.

In other words, you're going to have to implement your own validator class.

Community
  • 1
  • 1
Felipe Lema
  • 2,700
  • 12
  • 19