0
私はQTreeViewでうまく動作するモデルを持っています。私はこのようになりますソートを実装モデルでは:私はこの関数を呼び出すときQML TreeViewサポートは、モデルから放出されたlayoutChanged信号を出力しますか?
void SimpleTreeModel::sort(Node* sortedNode)
{
emit layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint);
QModelIndexList oldIndices = persistentIndexList();
Node::SortType sortType = Node::Down;
//sort starting node
sortedNode->sortChildren(sortType);
QModelIndexList newIndices;
newIndices.reserve(oldIndices.size());
for(const auto &i : oldIndices)
{
Node* node = const_cast<Node*>(nodeFromIndex(i));
QModelIndex index = indexFromNode(node);
newIndices.push_back(index);
}
changePersistentIndexList(oldIndices, newIndices);
QModelIndex startingIndex = indexFromNode(sortedNode);
emit layoutChanged({ QPersistentModelIndex(startingIndex) }, VerticalSortHint);
}
、QTreeViewは、ビューを更新しますが、QMLでツリービューには、これをしません。 QMLツリービュー用途:
TreeView
{
model: treeModel
TableViewColumn
{
title: "Title"
role: "title"
width: 700
}
}
私は間違っていますか?ソート後にビューが要素のレイアウトを更新しないのはなぜですか?
お返事ありがとうございます。しかし、私はこれがどのように役立つべきか理解できません。問題は、TreeViewがモデルからの信号に応答しないことです。 TreeViewのソースコードを読んだ後、モデルからlayoutChangedシグナルに応答する関数が見つかりませんでした。それは私を混乱させた。 –
@ strelok.ndvこのリンクを見ると、イメージが表示され、QMLビューとモデル間の通信にデリゲートが必要となります。http://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html – Naidu
答えも更新されました。 – Naidu