PDA

View Full Version : contents of QTableView cell are wiped out when one edits via double-click



pfeldman
15th October 2020, 22:40
I have a QTableView in which some cells contain long strings. When editing a cell via double click, it would be nice to be able to modify the string contents, e.g., add a few characters at the end, without re-typing the whole thing. Is there any way to prevent the contents from being wiped out when one goes into editing mode?

d_stranz
15th October 2020, 23:35
QAbstractItemView (from which QTableView inherits) has numerous signals that are emitted when the user interacts with cells. clicked(), doubleClicked(), activated(), entered(), and pressed() all send the QModelIndex for the cell. You can use that to retrieve the text of the cell.

In addition, if you have not implemented the EditRole for your QAbstractItemModel::data() method, then you should implement that role and return the current contents of the cell. That string will be loaded into the editor before it is displayed.