QApplication a(argc, argv);
QDirModel model; //QDirModel, 问文件目录树
QTreeView tree;
QListView list;
QTableView table;
// 共享同一份目录树
tree.setModel(&model);
list.setModel(&model);
table.setModel(&model);
// 选择的焦点,或者选中的模型共享,比如都选中第一个 或者第一个和第二个
tree.setSelectionMode(QAbstractItemView::MultiSelection);
list.setSelectionModel(tree.selectionModel());
table.setSelectionModel(tree.selectionModel());
// 对事件进行响应,当左侧树被双击,分别对其余两个进行更新,那么第一个呢?
QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex)),&list,SLOT(setRootIndex(QModelIndex)));
QObject::connect(&tree,SIGNAL(doubleClicked(QModelIndex)),&table,SLOT(setRootIndex(QModelIndex)));
QSplitter *splitter = new QSplitter;
splitter->addWidget(&tree);
splitter->addWidget(&list);
splitter->addWidget(&table);
splitter->setWindowTitle(QObject::tr("Model/View"));
splitter->show();