Hi, I am trying to create a tree view and a list view. The tree view should display only directories, and the list view should display only files. Clicking on a directory in the tree view should change the index of the list view. I tried this, having separate QDirModels, one each for the tree and list views:
tree.setModel(&dirModel);
list.setModel(&fileModel);
QDirModel dirModel;
QDirModel fileModel;
QTreeView tree(&window);
QListView list(&window);
tree.setModel(&dirModel);
list.setModel(&fileModel);
QObject::connect(&tree, SIGNAL(clicked(const QModelIndex &)),
&list, SLOT(setRootIndex(const QModelIndex &)));
To copy to clipboard, switch view to plain text mode
but the signals don't connect properly, ie, clicking on the tree view makes the list view go blank.
I also tried this, having a single QDirModel for both views:
model.
setFilter(QDir::Dirs |
QDir::NoDotAndDotDot);
tree.setModel(&model);
list.setModel(&model);
QObject::connect(&tree,
SIGNAL(clicked
()),
&list, SLOT(setCurrentIndex()));
QDirModel model;
QTreeView tree(&window);
QListView list(&window);
model.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
tree.setModel(&model);
list.setModel(&model);
QObject::connect(&tree, SIGNAL(clicked()),
&list, SLOT(setCurrentIndex()));
To copy to clipboard, switch view to plain text mode
The signal and slot here works, clicking the tree view changes the list view index, however only directories are displayed in both views.
Hints? Thanks!
Bookmarks