QTableView line edit clears the text on edit
Hi all.
Is there a way to alter the behavior of QTableView when editing a text cell to not clear the text in the cell when the cell is selected for editing?
For instance, I have a QTableView where the first column contains long text fields. It is impractical to have the user re-enter the entire contents just to change a single character.
I know I can do this by providing a custom widget for the column, but it seems like such standard behavior that there is a default implementation that I am missing.
Thanks!
Re: QTableView line edit clears the text on edit
That is strange. What did you set for view properties?
I have a table view like this:
Code:
view->setModel(model);
model->setTable("log");
view->setHorizontalHeader(header);
header->setMovable(TRUE);
And when I click in a table cell to edit, it highlights the cell, then if I double click, it highlights just the text for editing. Nothing goes away.
Re: QTableView line edit clears the text on edit
Thanks for the quick reply.
So it should behave the way I want by default? Very strange.
Here's my code which sets up the view:
Code:
ui->tableView->setColumnWidth(0, 200);
ui->tableView->setColumnWidth(1, 150);
ui->tableView->verticalHeader()->hide();
ui->tableView->horizontalHeader()->setStretchLastSection(true);
ui->tableView->resizeColumnsToContents();
I didn't see anything strange in there, but I tried commenting out all of the above and got the same behavior as before.
My platform is qt 4.6.2-1 running on kde 4.4.0. Do you think it could be a platform issue?
Thanks again.
Re: QTableView line edit clears the text on edit
I am currently seeing the same problem/behavior on Linux running Qt 4.5.3. The contents of an editable table cell are erased when the cell is selected. I would like them to remain untouched unless the user explictly deletes them.
Re: QTableView line edit clears the text on edit
Found a solution in this thread; add a clause to your model's data() routine that returns the item's data in editable form when called with a Qt::EditRole.
Re: QTableView line edit clears the text on edit
@SixDegrees:
Understandable that since this thread is old an answer to this request might go unspoken.
-Yet, do you have any example of the implementation you mentioned regarding the data() function in the model?
[currently experiencing a similar problem where the cell contents are deleted upon selection rather then inherently editable.