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 はデータベースから出てくるフラットなテーブルになるので、ツリーは返されません。
ツリー ビューにするための 2 つのオプションがあります。サブクラス化によって独自のモデルを作成するか、単に を構築するQStandardItemModelか、 を使用しQAbstractProxyModelて QSqlQuery テーブルの結果とグループ化されたツリー データ モデルとの間のマッピングを作成します。
QStandardItemModel
QAbstractProxyModel