PDA

View Full Version : [SOLVED] QTreeView, custom model and has-siblings style



stelek
26th July 2013, 22:53
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/stylesheet-examples.html#customizing-qtreeview
i created my own icons and my own stylesheet:



QTreeView::branch:has-siblings:!adjoins-item {
border-image: url(:/resources/icons/none-up-down.png) 0; }

QTreeView::branch:has-siblings:adjoins-item {
border-image: url(:/resources/icons/none-up-down-right.png) 0; }

QTreeView::branch:!has-children:!has-siblings:adjoins-item {
border-image: url(:/resources/icons/none-up-right.png) 0; }

QTreeView::branch:closed:has-children:has-siblings {
border-image: url(:/resources/icons/closed-up-down-right.png) 0; }

QTreeView::branch:closed:has-children:!has-siblings {
border-image: url(:/resources/icons/closed-up-right.png) 0; }

QTreeView::branch:open:has-children:!has-siblings {
border-image: url(:/resources/icons/open-up-right.png) 0; }

QTreeView::branch:open:has-children:has-siblings {
border-image: url(:/resources/icons/open-up-down-right.png) 0; }


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



|-A
|-B
|-C
|-D
|-E
|-F


I get something like this:



|-A
| |-B
| |-C
| |-D
| | |-E
| | |-F


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:



|-A
| |-B


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...
9371

stelek
27th July 2013, 01:35
Seems it was a problem with my parent() function. The enlightenment came after after reading this article:
http://ptgmedia.pearsoncmg.com/images/0131872494/samplechapter/blanchette_ch10.pdf
Highly recommended.