Results 1 to 5 of 5

Thread: How to show the leaf nodes of a treemodel in a listview?

  1. #1
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to show the leaf nodes of a treemodel in a listview?

    now, I come across a problem.
    1. I have a treeview and one treemodel(I use QStandardItemModel) correspondingly. The hierarchy may look like this:
    A
    -A1
    —A11
    —-A111
    -A2
    —A21
    —A22
    2. I have another view which is a listview.
    And I want to show the corresponding leaf nodes under which the user clicked.
    e.g. when the node A2 is clicked, the listview should show A21 and A22, and when A, it shows A111, A21 and A22.
    Is there any solution to this problem?
    And I use QSortFilterProxyModel and the function filterAcceptsRow, but it seams that when dealing with A2 that i return false, A21 and A22 wouldn’t be called by filterAcceptsRow() any more.
    Please help me.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to show the leaf nodes of a treemodel in a listview?

    e.g. when the node A2 is clicked, the listview should show A21 and A22, and when A, it shows A111, A21 and A22.
    Your requirement is very strange, do you really want A111, A21 and A22 when A is clicked, what it the logic behind it?

    And I use QSortFilterProxyModel
    You better implement custom QAbstractProxyModel
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    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: How to show the leaf nodes of a treemodel in a listview?

    Quote Originally Posted by Michael_BJFU View Post
    now, I come across a problem.
    1. I have a treeview and one treemodel(I use QStandardItemModel) correspondingly. The hierarchy may look like this:
    A
    -A1
    —A11
    —-A111
    -A2
    —A21
    —A22
    2. I have another view which is a listview.
    And I want to show the corresponding leaf nodes under which the user clicked.
    e.g. when the node A2 is clicked, the listview should show A21 and A22, and when A, it shows A111, A21 and A22.
    Is there any solution to this problem?
    Yes. You need a custom proxy model (not a QSortFilterProxyModel) that will scan your base model and assemble the proxy accordingly. I have done something like that once and it worked ok.
    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.


  4. #4
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show the leaf nodes of a treemodel in a listview?

    Quote Originally Posted by Santosh Reddy View Post
    Your requirement is very strange, do you really want A111, A21 and A22 when A is clicked, what it the logic behind it?
    Just like in Visual Studio, when creating a new project, you can choose the global category on the left and choose the project type on right. VS.jpg

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to show the leaf nodes of a treemodel in a listview?

    Just like in Visual Studio, when creating a new project, you can choose the global category on the left and choose the project type on right.
    Ahh, I get it.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. to show Checkboxes in listview
    By Ketan Shah in forum Newbie
    Replies: 3
    Last Post: 23rd May 2011, 09:01
  2. TreeModel from TableModel
    By baray98 in forum Qt Programming
    Replies: 3
    Last Post: 21st May 2011, 00:06
  3. Replies: 3
    Last Post: 9th December 2010, 21:10
  4. About TreeModel and TreeItem?
    By yangyunzhao in forum Qt Programming
    Replies: 2
    Last Post: 14th August 2009, 07:25
  5. Changing the text color of a QTreeView leaf.
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 22nd March 2006, 23:58

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.