int main(int argc, char**argv)
{
//------ test proxy and setIndexWidget
//-- model
for (int i=0; i<4; ++i) {
parent = testModel.index(0,0,parent);
testModel.insertRows(0,1,parent);
testModel.insertColumns(0,1,parent);
testModel.setData(index,i);
}
//-- tree and filtered tree
tree.setModel(&testModel);
tree.setWindowTitle("direct");
tree.show();
filter.setSourceModel(&testModel);
filteredTree.setModel(&filter);
filteredTree.setWindowTitle("filtered");
filteredTree.show();
//-- add buttons
button1->setText("button1");
tree.setIndexWidget(modelIndex,button1);
QModelIndex filterIndex
= filter.
mapFromSource(modelIndex
);
button2->setText("button2");
filteredTree.setIndexWidget(filter.mapFromSource(modelIndex),button2);
//-- change model
testModel.
setData(testModel.
index(0,
0,
QModelIndex()),
42);
//-- add buttons
button3->setText("button3");
tree.setIndexWidget(modelIndex,button3);
filterIndex = filter.mapFromSource(modelIndex);
button4->setText("button4");
filteredTree.setIndexWidget(filterIndex,button4);
//-- add again button, normal ?
//-- doesn't work with the same (button2) ? is it destroyed when the model changes ?
//modelIndex = testModel.index(1,0,QModelIndex());
//filterIndex = filter.mapFromSource(modelIndex);
//QToolButton * button5 = new QToolButton(&filteredTree);
//button5->setText("button5");
//filteredTree.setIndexWidget(filter.mapFromSource(modelIndex),button5);
//-- run
application.exec();
return 0;
}
int main(int argc, char**argv)
{
//------ test proxy and setIndexWidget
QApplication application(argc,argv);
//-- model
QStandardItemModel testModel;
QModelIndex parent;
for (int i=0; i<4; ++i) {
parent = testModel.index(0,0,parent);
testModel.insertRows(0,1,parent);
testModel.insertColumns(0,1,parent);
QModelIndex index = testModel.index(0,0,parent);
testModel.setData(index,i);
}
//-- tree and filtered tree
QTreeView tree;
tree.setModel(&testModel);
tree.setWindowTitle("direct");
tree.show();
QSortFilterProxyModel filter;
filter.setSourceModel(&testModel);
QTreeView filteredTree;
filteredTree.setModel(&filter);
filteredTree.setWindowTitle("filtered");
filteredTree.show();
//-- add buttons
QModelIndex modelIndex = testModel.index(0,0,QModelIndex());
QToolButton * button1 = new QToolButton(&tree);
button1->setText("button1");
tree.setIndexWidget(modelIndex,button1);
QModelIndex filterIndex = filter.mapFromSource(modelIndex);
QToolButton * button2 = new QToolButton(&filteredTree);
button2->setText("button2");
filteredTree.setIndexWidget(filter.mapFromSource(modelIndex),button2);
//-- change model
testModel.insertRows(0,1,QModelIndex());
testModel.setData(testModel.index(0,0,QModelIndex()),42);
//-- add buttons
modelIndex = testModel.index(0,0,QModelIndex());
QToolButton * button3 =new QToolButton(&tree);
button3->setText("button3");
tree.setIndexWidget(modelIndex,button3);
filterIndex = filter.mapFromSource(modelIndex);
QToolButton * button4 = new QToolButton(&filteredTree);
button4->setText("button4");
filteredTree.setIndexWidget(filterIndex,button4);
//-- add again button, normal ?
//-- doesn't work with the same (button2) ? is it destroyed when the model changes ?
//modelIndex = testModel.index(1,0,QModelIndex());
//filterIndex = filter.mapFromSource(modelIndex);
//QToolButton * button5 = new QToolButton(&filteredTree);
//button5->setText("button5");
//filteredTree.setIndexWidget(filter.mapFromSource(modelIndex),button5);
//-- run
application.exec();
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks