QTreeView branch rendering

  • One of the stylesheet "examples":http://doc.qt.nokia.com/4.7-snapshot/stylesheet-examples.html#customizing-qtreeview suggests using png files to implement vertical and horizontal lines in QTreeView.

    It's a very old approach, and a bad one, because the height of the elements in the tree view is variable. Something as simple as using a different font or a different screen resolution makes those images the wrong height. So either the images get stretched, and look awful, or they don't get stretched, and look even worse. It's one of those things that really wants to be rendered dynamically.

    Does anybody know a good (i.e. properly scaling) approach for doing this, or do I need to specialize QTreeView myself?

  • -You could subclass the delegate and do your own rendering there.-
    Note that I find your example a bit artificial. If you go around messing with style sheets to style this aspect of the tree view, then I think it is reasonable to assume that you also control the fontsize and other size aspects of the tree view.

    -Still, the delegate approach is more flexible.-

    Branches are not rendered by the delegate, but by the tree view. Sorry! It seems that indeed you will need to subclass either the QTreeView, or perhaps use a proxy style.

  • Indeed. And it wasn't that I wanted to be messing around with style sheets. It was rather the case that style sheets seemed to be the "suggested" way to make the tree view draw its branches. If there is a better/simpler way to get that, I'm all in favor of it!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.