gimmejimmy
24th June 2009, 07:19
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:
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 &)));
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:
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()));
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!
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 &)));
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:
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()));
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!