вторник, 11 января 2011 г.

The Interview Framework (QListView)

Sharing a Model Between Views

In this example, we display the contents of a model using two different views, and share the user's selection between them. We will use the QDirModel supplied with Qt because it requires very little configuration, and provides existing data to the views.

The main() function for this example demonstrates all the principles involved in setting up a model and two views. We also share the selection between the two views:

    int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSplitter *splitter = new QSplitter;

QDirModel *model = new QDirModel;
QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);
tree->setRootIndex(model->index(QDir::currentPath()));

QListView *list = new QListView(splitter);
list->setModel(model);
list->setRootIndex(model->index(QDir::currentPath()));

QItemSelectionModel *selection = new QItemSelectionModel(model);
tree->setSelectionModel(selection);
list->setSelectionModel(selection);

splitter->setWindowTitle("Two views onto the same directory model");
splitter->show();
return app.exec();
}
source