Answer the question
In order to leave comments, you need to log in
Qt4. Incorrect rendering of a hierarchical model when setting a proxy model that swaps columns?
Hello gentlemen!
There is a custom hierarchical model inherited from QAbstractItemModel. Written its own proxy model. Inherited from QSortFilterProxyModel'i (overridden methods: data, setData, headerData, mapToSource, mapFromSource, hasChildren, rowCount). In addition to the functionality of QSortFilterProxyModel, it also knows how to throw out some columns, as well as swap the rest. Everything works if the null column from the original model matches the null column in the proxy model. If the proxy model moves this column, then the display is incorrect: Arrows (or crosses) are drawn correctly - opposite those elements that have descendants. But when you try to open such an element, it turns out that there are no elements inside.
Here are some proxy model methods:
bool MySortFilterProxyModel::hasChildren(const QModelIndex &parent) const
{<br/>
if (parent.isValid() && parent.column() != 0)<br/>
return false;<br/>
<br/>
QModelIndex source_parent = mapToSource(parent);<br/>
return sourceModel()->hasChildren( source_parent.sibling(source_parent.row(), 0) );<br/>
}<br/>
<br/>
int MySortFilterProxyModel::rowCount(const QModelIndex &parent) const<br/>
{<br/>
if (parent.isValid() && parent.column() != 0)<br/>
return 0;<br/>
<br/>
QModelIndex source_parent = mapToSource(parent);<br/>
return sourceModel()->rowCount( source_parent.sibling(source_parent.row(), 0) );<br/>
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question