tags:

views:

487

answers:

1

Dear All,

first I apologize for the probably silly question. I am having trouble with QT. I have a table widget 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? Can I find some tutorial anywhere? Thanks!!!

Cheers

Giuseppe

+2  A: 

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.

swongu
Thanks. One question only: how do I set the validator for a column? I did it for a QLineEdit, but never for columns.
Giuseppe
The validator is set onto the editor `QLineEdit`. Since the delegate handles creating editors for cells, you can set different delegates for different columns - just use `QAbstractItemView::setItemDelegateForColumn()`.
swongu
I would suggest the possibility of using a spin box and double spin box for the delegate editors instead. They can still be typed in, already have the validators, and additionally allow the user to quickly increment/decrement the value.
Caleb Huitt - cjhuitt