I'm working with a Qtreeview and I'm facing some problems having the treview shown when either the first column is hidden or when I rearrange the tree.
I'm using a custom model where I've tried to put in a 'branch column' (m_branchcolumn see below) to map the parent to the first visible column in the treeview but it doesn't work. I always see the treeview nodes (the plus and minus signs) in column zero. I'm using an internal record representation like the nodeitem from the simple treeview example shipped with Qt.
{
if (!child.isValid())
Record *rec = recordFromIndex(child);
if (!rec)
Record *parentRecord = rec->parent;
if (!parentRecord)
if(parentRecord == rootRecord)
Record *grandparentRecord = parentRecord->parent;
if (!grandparentRecord)
int row = grandparentRecord->children.indexOf(parentRecord);
return createIndex(row, m_branchcolumn, parentRecord);
}
QModelIndex ViewModel::parent(const QModelIndex &child) const
{
if (!child.isValid())
return QModelIndex();
Record *rec = recordFromIndex(child);
if (!rec)
return QModelIndex();
Record *parentRecord = rec->parent;
if (!parentRecord)
return QModelIndex();
if(parentRecord == rootRecord)
return QModelIndex();
Record *grandparentRecord = parentRecord->parent;
if (!grandparentRecord)
return QModelIndex();
int row = grandparentRecord->children.indexOf(parentRecord);
return createIndex(row, m_branchcolumn, parentRecord);
}
To copy to clipboard, switch view to plain text mode
How can I make sure always to show the tree branches in the far left visible column even after column change and with hidden columns?
Bookmarks