Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QModelIndex: Get for same column in parent?
nonot1 last edited by
I'm working with the sample code at:
Given a QModelIndex pointing at a certain item, how do I get a QModelIndex for the item's parent that points to the same column?
Just calling someIndex.parent() will always return a QModelIndex with column == 0.
In this sample case, since each row has the same number of columns, so we know for sure that every parent (other than the invisible root) certainly has such a column.
What is the correct method?
andre last edited by
You could do something like this:
QModelIndex parent = someIndex.parent();
QModelIndex parentColumn = someIndex.model().index(parent.parent(), parent.row(), someIndex.column());