View Full Version : QTableView line edit clears the text on edit
PlasticJesus
1st March 2010, 23:23
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!
waynew
2nd March 2010, 01:05
That is strange. What did you set for view properties?
I have a table view like this:
model = new QSqlTableModel(this, logdb);
view = new QTableView();
view->setModel(model);
model->setTable("log");
header = new QHeaderView(Qt::Horizontal, this);
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.
PlasticJesus
2nd March 2010, 01:23
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:
ui->tableView->setColumnWidth(0, 200);
ui->tableView->setColumnWidth(1, 150);
ui->tableView->verticalHeader()->hide();
ui->tableView->horizontalHeader()->setStretchLastSection(true);
ui->tableView->resizeColumnsToContents();
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelectio n);
ui->tableView->setEditTriggers(QAbstractItemView::DoubleClicked);
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.
SixDegrees
20th April 2010, 02:00
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.
SixDegrees
20th April 2010, 20:06
Found a solution in this thread (http://www.qtcentre.org/threads/30013-TableView-Model-Display-Question); add a clause to your model's data() routine that returns the item's data in editable form when called with a Qt::EditRole.
jkrienert
14th March 2015, 20:06
@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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.