[SOLVED] QTreeView - changing the value of an item in a row when a value in an item on the same row changes
-
I have a row in my QTreeView which has been created with 4 * QStandardItem (using setChild(row, column, item)).
The user has clicked on column 3 and edited it. I get that item (using m_model->itemFromIndex(index)). Now I want to update the item in column 1 on the same row. How do I get a pointer to it? All I have is the index of the item in column 3 which was edited.
-
Hi.
You have row index ("QModelIndex::row()":http://qt-project.org/doc/qt-4.8/qmodelindex.html#row), so you can get QModelIndex (i.e. model->index(rowIndex, 0)) of desired column -
@// obtain the index to the element in the same row in column 1
QModelIndex target_index = m_model->index(edited_item_index.row(), 1, edited_item_index.parent());
// change data in the desired item
m_model->setData(target_index, newdata);@I think you get the idea :)
-
That works thanks. Happy dance :-)