1
votes

Is there a way to set the max length of a QTableWidget item (table cell)? I have a table that is editable and I would like the max length to be 3 when a user is editing a cell.

2

2 Answers

1
votes

Create a subclass of QStyledItemDelegate and grab the QLineEdit that is created for the cells. You can use QLineEdit::setMaxLength(int) to set the maximum length that you want.

See the documentation of QStyledItemDelegate

0
votes
tableWidget->setColumnWidth(column_number, length) 

but 3 is small value for length, try with 30.