Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我使用此代码。
model = new QSqlQueryModel(this); model->setQuery("select id,parent,name from table"); tree = new QTreeView(this); tree->setModel(model);
在 TreeView 中显示表格,但不显示树。如何显示树?
好吧,它不会返回树,因为 QSqlQueryModel 会生成一个从数据库中出来的平面表。
您有两个选项可以将其制成树视图,通过子类化或仅构建一个创建自己的模型QStandardItemModel,或使用一个QAbstractProxyModel创建 QSqlQuery 表结果与分组树数据模型之间的映射。
QStandardItemModel
QAbstractProxyModel