QT目录模型QDirModel的使用(一个model同时连接tree,list,table)
3#include <QApplication>
#include <QAbstractItemModel>
#include <QAbstractItemView>
#include <QItemSelectionModel>
#include <QDirModel>
#include <QTreeView>
#include <QListView>
#include <QTableView>
#include <QSplitter>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QDirModel model;
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();
return app.exec();
}
---------------------
作者:yunshouhu
来源:CSDN
原文:https://blog.csdn.net/earbao/article/details/8941923
版权声明:本文为博主原创文章,转载请附上博文链接!