Qml TreeView 默认全部展开
TreeView在更新模型后所有节点默认为折叠状态,默认展开方法如以下代码:
TreeView {
id: treeview; Layout.fillWidth: true; Layout.fillHeight: true; Layout.margins: 10; Layout.topMargin: 0;
UseTv.TableViewColumn { title: "文件/序号"; role: "file"; width: 200; }
UseTv.TableViewColumn { title: "时间/数据"; role: "time"; width: 300; }
model: BackEnd.tree_model();
itemDelegate: Item {
Text {
anchors.verticalCenter: parent.verticalCenter; color: styleData.textColor; elide: styleData.elideMode; text: styleData.value;
}
onVisibleChanged: {
if (!visible)
return;
if (styleData.hasChildren && styleData.column === 0) {
treeview.expand(styleData.index);
}
}
}
}