Results 1 to 3 of 3

Thread: One Model, Two Views (QTreeView and QTableView)

  1. #1
    Join Date
    Sep 2009
    Location
    Orange, California, USA
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question One Model, Two Views (QTreeView and QTableView)

    I created a custom model that stores some data as a tree. When I set the model of the QTreeView with my model, it displays correctly. When I set the model of the QTableView with my model only the root node is displayed, as expected.

    What would be the best way to have the QTableView display the leaf nodes of the tree, depending on what node is selected? I don't want to create a new model for the QTableView, because I want single clicks on items in the QTreeView to have the same functionality as double clicking on items in the QTableView.

    Example: here is a model stored as a tree. A is the root, B and E are children of A, C and D are children of B, F and G are children of E.

    A
    ----B
    --------C
    --------D
    ----E
    --------F
    --------G

    If A is selected in the QTreeView, then C, D, F and G would be displayed in the QTableView.
    if B is selected in the QTreeView, then C and D are displayed in the QTableView.
    if E is selected in the QTreeView, then F and G are displayed in the QTableView.

    I'm trying to avoid creating a custom view for the table. Doing that seems very complicated. I've been looking at using the QSortFilterProxyModel, but not sure if this is going to do what I need.

    Again, I want the selection of the item in the QTreeView to initiate the same action as the selection of the item in the QTableView. My custom model has custom items that store information about devices on a network. So I need the QTreeView and QTableView to be connected.

    Any thoughts on how to do this?

    Thanks,
    -David
    Last edited by dgarrett97; 11th September 2009 at 23:41.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: One Model, Two Views (QTreeView and QTableView)

    You need to provide a custom proxy model for your model.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Location
    Orange, California, USA
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: One Model, Two Views (QTreeView and QTableView)

    Thank you very much for your reply.
    -David

Similar Threads

  1. row height in QTreeView and QTableView
    By yuriry in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2008, 00:58
  2. QTreeView Fixed column & QTableView
    By jpujolf in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2008, 09:35
  3. QTableView vs QTreeView
    By aamer4yu in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2008, 07:17
  4. How to merge QTableView and QTreeView ???
    By Xaleandr in forum Newbie
    Replies: 2
    Last Post: 29th December 2007, 17:58
  5. using QTreeView with a Database model
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2007, 23:29

Tags for this Thread

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.