Reputation: 4538
I have a table widget. I can't figure out how to change input format in each of the cells. At the moment I want it to only accept hex values. How do I do that? I'm using Qt Designer 4.8.6 and PyQt4
Any help is appreciated.
Upvotes: 1
Views: 332
Reputation: 1060
that can be done using a custom Delegate and QRegexValidator :
you have to create a custom Delegate where you override the method :
QWidget createEditor (self, QWidget parent, QStyleOptionViewItem option, QModelIndex index)
so it will return a QLineEdit that have a QRegexValidator, containing the correct pattern.
To set the regex validor on the QLineEdit use :
setValidator (self, QValidator)
finally, set the custom Delegate on your Table using :
setItemDelegate (self, QAbstractItemDelegate delegate)
Upvotes: 1