Results 1 to 2 of 2

Thread: [SOLVED] QTreeView, custom model and has-siblings style

  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question [SOLVED] QTreeView, custom model and has-siblings style

    Hi all,
    I'm implementing a QTreeView with a custom model. I managed to solve most of the problems and I finally seem to understand how the QModelIndex works. However, I've decided to add "tree structure lines" to my visualization and I ran into another problem.

    Based on the description here:
    http://doc.qt.digia.com/4.7/styleshe...zing-qtreeview
    i created my own icons and my own stylesheet:

    Qt Code:
    1. QTreeView::branch:has-siblings:!adjoins-item {
    2. border-image: url(:/resources/icons/none-up-down.png) 0; }
    3.  
    4. QTreeView::branch:has-siblings:adjoins-item {
    5. border-image: url(:/resources/icons/none-up-down-right.png) 0; }
    6.  
    7. QTreeView::branch:!has-children:!has-siblings:adjoins-item {
    8. border-image: url(:/resources/icons/none-up-right.png) 0; }
    9.  
    10. QTreeView::branch:closed:has-children:has-siblings {
    11. border-image: url(:/resources/icons/closed-up-down-right.png) 0; }
    12.  
    13. QTreeView::branch:closed:has-children:!has-siblings {
    14. border-image: url(:/resources/icons/closed-up-right.png) 0; }
    15.  
    16. QTreeView::branch:open:has-children:!has-siblings {
    17. border-image: url(:/resources/icons/open-up-right.png) 0; }
    18.  
    19. QTreeView::branch:open:has-children:has-siblings {
    20. border-image: url(:/resources/icons/open-up-down-right.png) 0; }
    To copy to clipboard, switch view to plain text mode 

    It almost works. The problem is that instead of such tree:

    Qt Code:
    1. |-A
    2. |-B
    3. |-C
    4. |-D
    5. |-E
    6. |-F
    To copy to clipboard, switch view to plain text mode 

    I get something like this:

    Qt Code:
    1. |-A
    2. | |-B
    3. | |-C
    4. | |-D
    5. | | |-E
    6. | | |-F
    To copy to clipboard, switch view to plain text mode 

    So for some reason the QTreeView seems to think that all my nodes have siblings while they really don't. I expected the problem to be with my rowCount() but I double-checked it and the returned value is always proper. I even hardcoded "return 1" there and still got a tree like that:

    Qt Code:
    1. |-A
    2. | |-B
    To copy to clipboard, switch view to plain text mode 

    Actually part of that tree is correct - the part next to B uses the the correct icon (without "down" connection), so the has-siblings property works properly there. It's just the vertical line that appears for a reason that is not clear to me. Any help will be appreciated.

    And a picture. That's a complete tree...
    treeviewstylesheet.png
    Last edited by stelek; 27th July 2013 at 00:35.

  2. #2
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView, custom model and has-siblings style

    Seems it was a problem with my parent() function. The enlightenment came after after reading this article:
    http://ptgmedia.pearsoncmg.com/image...hette_ch10.pdf
    Highly recommended.

Similar Threads

  1. Replies: 1
    Last Post: 22nd October 2012, 10:02
  2. Custom model for QTreeView with SQLite data source
    By emanuel in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2011, 00:53
  3. QTreeView and custom model from QAbstractItemModel
    By croscato in forum Qt Programming
    Replies: 5
    Last Post: 18th January 2010, 16:03
  4. Replies: 1
    Last Post: 24th September 2009, 13:44
  5. Updating QTreeView with custom model
    By supergillis in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 07:01

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.