Reputation: 1820
I made a TreeView using QStandardItemModel like below image A
and I also have a QStandardItemModel like below image B
Now, I want mix two Model together to made a new Model for a TreeView
new TreeView has like below image C:
Example:
QStandardItemModel * fileTree = new QStandardItemModel();
QStandardItemModel * zipTree = new QStandardItemModel();
QStandardItemModel * fullTree = new QStandardItemModel();
......
......
fileTree is model for TreeView image A;
zipTree is model for TreeView image B;
How to mix them to make fullTree for TreeView image C.
update:
3 data have both a model, only data is different. I want to merge data for photo C form A + B. file a.zip -> folder a. and add file list of a (image B) to new folder (a)
P/S: Don't using QfileSystemModel
Upvotes: 0
Views: 536
Reputation: 4484
QTreeView t;
QStandardItemModel a;
t.setModel(&a);
t.show();
I simplified the Image A
, construct it as below:
QStandardItem* folder1 = new QStandardItem("folder1");
QStandardItem* zip = new QStandardItem("a.zip");
a.appendRow(folder1);
folder1->appendRow(zip);
Construct Image B
:
QStandardItemModel b;
b.appendRow(new QStandardItem("filea"));
b.appendRow(new QStandardItem("fileb"));
b.appendRow(new QStandardItem("filec"));
"Mix" both as Image C
:
zip->setText(zip->text().remove(".zip"));
for (int i = 0; i < b.rowCount(); i++) {
zip->appendRow(b.takeItem(i));
}
Upvotes: 1