//! [0] //! [1] int main(int argc, char *argv[]) { QApplication app(argc, argv); QSplitter *splitter = new QSplitter; //! [2] //! [3] QDirModel *model = new QDirModel; //! [0] //! [2] //! [4] //! [5] QTreeView *tree = new QTreeView(splitter); //! [3] //! [6] tree->setModel(model); //! [4] //! [6] //! [7] tree->setRootIndex(model->index(QDir::currentPath())); //! [7] QListView *list = new QListView(splitter); list->setModel(model); list->setRootIndex(model->index(QDir::currentPath())); //! [5] QItemSelectionModel *selection = new QItemSelectionModel(model); tree->setSelectionModel(selection); list->setSelectionModel(selection); //! [8] splitter->setWindowTitle("Two views onto the same directory model"); splitter->show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication a(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 a.exec(); }
int main( int argc, char **argv ) { QApplication app( argc, argv ); QTreeView *tree = new QTreeView(); QListView *list = new QListView(); QTableView *table = new QTableView(); QSplitter splitter; splitter.addWidget(tree); splitter.addWidget(list); splitter.addWidget(table); QStandardItemModel model( 5, 2 ); for( int r=0; r<5; r++ ) { for( int c=0; c<2; c++) { QStandardItem *item = new QStandardItem(QString("Row:%0, Column:%1").arg(r).arg(c)); if(c == 0) { for(int i=0; i<3; i++) { QStandardItem *child = new QStandardItem(QString("Item %0").arg(i)); child->setEditable(false); item->appendRow(child); } } model.setItem(r, c, item); } } model.setHorizontalHeaderItem(0, new QStandardItem("Foo")); model.setHorizontalHeaderItem(1, new QStandardItem("Bar-Baz")); tree->setModel(&model); list->setModel(&model); table->setModel(&model); list->setSelectionModel(tree->selectionModel()); table->setSelectionModel(tree->selectionModel()); table->setSelectionBehavior(QAbstractItemView::SelectRows); table->setSelectionMode(QAbstractItemView::SingleSelection); splitter.show(); MainWindow w; w.show(); return app.exec(); }
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(interview); QApplication app(argc, argv); QSplitter page; QAbstractItemModel *data = new Model(1000, 10, &page); QItemSelectionModel *selections = new QItemSelectionModel(data); QTableView *table = new QTableView; table->setModel(data); table->setSelectionModel(selections); table->horizontalHeader()->setMovable(true); table->verticalHeader()->setMovable(true); // Set StaticContents to enable minimal repaints on resizes. table->viewport()->setAttribute(Qt::WA_StaticContents); page.addWidget(table); QTreeView *tree = new QTreeView; tree->setModel(data); tree->setSelectionModel(selections); tree->setUniformRowHeights(true); tree->header()->setStretchLastSection(false); tree->viewport()->setAttribute(Qt::WA_StaticContents); // Disable the focus rect to get minimal repaints when scrolling on Mac. tree->setAttribute(Qt::WA_MacShowFocusRect, false); page.addWidget(tree); QListView *list = new QListView; list->setModel(data); list->setSelectionModel(selections); list->setViewMode(QListView::IconMode); list->setSelectionMode(QAbstractItemView::ExtendedSelection); list->setAlternatingRowColors(false); list->viewport()->setAttribute(Qt::WA_StaticContents); list->setAttribute(Qt::WA_MacShowFocusRect, false); page.addWidget(list); page.setWindowIcon(QPixmap(":/images/interview.png")); page.setWindowTitle("Interview"); page.show(); return app.exec(); }
void Test_FileSystem_MVC() { QSplitter* splitter = new QSplitter;//two widget QFileSystemModel* model = new QFileSystemModel; QTreeView* tree = new QTreeView(splitter);//left tree view QListView* list = new QListView(splitter);//right list view splitter->setWindowTitle("Two vies onto the same file system model"); model->setRootPath(QDir::currentPath()); tree->setModel(model);//set model for view tree->setRootIndex(model->index(QDir::currentPath())); list->setModel(model); list->setRootIndex(model->index(QDir::currentPath())); list->setSelectionModel(tree->selectionModel()); splitter->show(); }