Hi,
I want to fix the maximum characters that a user can input in a qtablewidgetitem.
I was thinking of validators, but I'm not sure how to do it.
Any hints?
Thanks
Hi,
I want to fix the maximum characters that a user can input in a qtablewidgetitem.
I was thinking of validators, but I'm not sure how to do it.
Any hints?
Thanks
QTableWidget uses a QLineEdit to edit the contents of an item. The QLineEdit is provided by the QItemDelegate installed for every column. You can use QLineEdit::setMaxLength to fix the maximum number of characters.
Do the following:
- Create a subclass of QItemDelegate.
- Override QItemDelegate::createEditor (see code below).
- Install your ItemDelegate in the QTableWidget using setItemDelegate , setItemDelegateForColumn, or setItemDelegateForRow as appropriate.
Qt Code:
{ lineEdit->setMaxLength(80); // or whatever... return lineEdit; }To copy to clipboard, switch view to plain text mode
Bookmarks