QTableWidget, allow to type numbers only

4.3k views Asked by At

I have a QTableWidget with four columns. I want the user to be able to insert only integers in the first three and a double in the fourth.

I believe that this can be done with delegate, but I have not found relevant examples (only some with QDateTimeEdit).

What should I do?

1

There are 1 answers

3
swongu On

Look at the documentation for QItemDelegate; it provides a pretty good description on how it can be used.

Since with a delegate, you'll be able to provide your own custom editor, I would suggest that you use a QLineEdit with a validator set using setValidator(). I believe the classes QIntValidator and QDoubleValidator will be perfect in this situation.