PDA

View Full Version : [Self-Solved] How to update a table view row area handled by an itemdelegate?



hickscorp
7th June 2011, 15:25
Hello,

i have a setup which involves two QTableViews. Both are linked to custom models (SQL derived), and basically acts as a hierarchy view (First QTableView displays objects of first database table, upon click on them the belonging objects from another database table are displayed on the second QTableView).

On the first QTableView, there is a "virtual column" displaying a summary of what's belonging to the first type. Actually, this virtual column display the count of children matching a condition. This very column is handled by a very simple text-ish item delegate.

However, here is my problem. If i select an item from my first table, then the cascading children are displayed on my second table. At this point, if i change data on the second table, i would like to be able to update the "count" column on the first time in real-time... But i have no idea how to do that.

i an actually catching any modification made on objects from the 2nd table model, but i'm not sure what to do in that method (dataChanged slot). Do i have to force the painting of the item-delegate generated widget of the first table? Can i notify the first table that the data of the "count" virtual column has changed in a special way?

Thanks a lot!
Pierre.

Santosh Reddy
7th June 2011, 15:40
You should inform the first view's model to update all the views connected to it.

hickscorp
7th June 2011, 17:22
Hello Santosh and thanks for your help,


You should inform the first view's model to update all the views connected to it.
i actually know that... That's what i'm asking here, how can i do that? i have tried a lot of various things already... For instance:

_dtModel->setData(curIndex, sameData) to force repaint...
But this solution is very bad for me, because it triggers a de-selection on the first table... How can i just "notify" as you say, that only a small portion of data has changed, and that just the redraw of one small cell has to be done?

Thanks,
Pierre.

Added after 1 19 minutes:

Ok... i finally have found the solution to my problem. In my first model, i have defined a public method as follows:

void triggerUpdate (QModelIndex const &idx) {
emit dataChanged(idx, idx);
}
Then on my main window code, where i catch changes from my 2nd model, i do that:


QModelIndex i = ui.tblVwDocumentTypes->selectionModel()->currentIndex();
QModelIndex fi = _dtModel->index(i.row(), DocumentTypesModel::ColumnIndexStatus, i.parent());
((DocumentTypesModel*)_dtModel)->triggerUpdate(fi);


Solved.
Pierre.