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.
virtual QWidget* MyItemDelegate
::createEditor(QWidget* parent,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
lineEdit->setMaxLength(80); // or whatever...
return lineEdit;
}
virtual QWidget* MyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
QLineEdit* lineEdit = new QLineEdit(parent);
lineEdit->setMaxLength(80); // or whatever...
return lineEdit;
}
To copy to clipboard, switch view to plain text mode
Bookmarks