Results 1 to 3 of 3

Thread: QDirModel, QTreeView, and QListView

  1. #1

    Default QDirModel, QTreeView, and QListView

    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:
    Qt Code:
    1. QDirModel dirModel;
    2. QDirModel fileModel;
    3. QTreeView tree(&window);
    4. QListView list(&window);
    5. tree.setModel(&dirModel);
    6. list.setModel(&fileModel);
    7. QObject::connect(&tree, SIGNAL(clicked(const QModelIndex &)),
    8. &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:
    Qt Code:
    1. QDirModel model;
    2. QTreeView tree(&window);
    3. QListView list(&window);
    4. model.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
    5. tree.setModel(&model);
    6. list.setModel(&model);
    7. QObject::connect(&tree, SIGNAL(clicked()),
    8. &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!

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDirModel, QTreeView, and QListView

    the slot setRootIndex aspects the QModelIndex of the same view. but u are passing the modelIndex of tree into the list. so the setRootIndex treat it as an invalid index.

  3. #3

    Default Re: QDirModel, QTreeView, and QListView

    So it's not possible to use separate QDirModels for tree and list and connect them? Can I use an intermediary modelIndex?
    Or if I use a single QDirModel for both of them can I have separate filters for each view?

Similar Threads

  1. Replies: 5
    Last Post: 5th March 2009, 13:52
  2. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 22:22
  3. QDirModel
    By L.Marvell in forum Newbie
    Replies: 2
    Last Post: 5th June 2007, 15:47
  4. Qt4 QTreeView vs Qt3 QListView
    By mcostalba in forum Qt Programming
    Replies: 6
    Last Post: 9th January 2007, 16:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.