Unsolved Expand cell of QTableWidget when click on it
-
Hello,
I am using a QTableWidget to display some data, with the option horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch), so that the columns fit the width of my widget. Also the cells are not editable.
The problem I have here is that with the stretch option, the columns are not resizable, and if the text is too long on a cell, we can't see it entirely. So what I would like to do is to expand the cell to fit the entire text, when the user click on it. It is already done when the cell is in mode "editable". Like in the following picture :
Is there a simple way to do the same, even when the mode is not editable?
Thank you and regards,
Emmanuel
-
@EmmanuelC
The simplest would be to look at https://doc.qt.io/qt-5/qtableview.html#resizeColumnToContents. This would resize the whole column for the longest visible content, you'd have to decide whether that is acceptable. I don't know of an in-built "resize column for content of only one cell", you would have to go via https://doc.qt.io/qt-5/qtableview.html#sizeHintForColumn and measure the text width for that.In the edit case the current editable text is allowed to spill/span across columns, and without affecting the column width. This isn't going to work when displaying the whole column.