QTableView commit data in code
-
Meanwhile, my solution is something like (inside my manual save function)
@
QModelIndex ndx = ui->tableView->currentIndex();
if (ndx.isValid()) {
ui->tableView->setCurrentIndex( tbl->index(ndx.row(), 0));
ui->tableView->setCurrentIndex( tbl->index(ndx.row(), 1));
}
@
which only works if there are at least 2 columns, but at least it works. -
Seems a mislanding in the HTML, I wanted to point you to the very first reply in that thread. This works for every type of cell editor. The comment about the combo boxes was related to the code snippets later on.
-
Ok... if I understand it correctly though, it can only work with subclassing?
-
No. Just call that mentioned endEdit() method whenever you want to be sure that all editors are closed (eg. in a save or check method).
-
You are talking about QTableView's endEdit() function?
Isn't that a protected function (so I need to subclass QTableView)? -
No, I talk about a method in another class. You can happily name it like you want, eg.
@
void closeThatFunkyEditorBecauseQtDoesNot();
@ -
I'm sorry for insisting, but I don't understand something.
You are talking about a function that contains
@
void AnyClass::endEdit()
{
QModelIndex index = myTblVw->currentIndex();
myTblVw->currentChanged( index, index );
}
@
How do I get access to the auto-generated text edit of the QTableView, so I can wire it to this slot?
Also, isn't currentChanged protected too? -
You do not wire this to a signal of the editor. Just call this method in your slot connected to the save button before you actually do the save.
-
I must be missing something very obvious here, because it's not working for me.
Inside my Qt class that owns the QTableView (say it's a variable named myTblVw) , I can't call
myTblVw->currentChanged(...) from my save() slot because it's a protected method.So you are saying I should create another class deriving from anything, and write a function like in the previous posts? How does that class get access to the QTableView? Even if I were to pass a pointer to myTblVw, it still won't be able to call the protected method.
How is this going to work without subclassing? -
Yes, you're right, sorry. I have it in a QXyzView subclass and thus can call slot currentChanged() this way.