QTableWidget, allow to type numbers only
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 sho开发者_开发知识库uld I do?
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.
精彩评论