PDA

View Full Version : Tree sample code



nuliknol
24th January 2015, 15:41
Hi,
I am looking for sample code of the tree, with "+" and "-" signs to traverse the tree. I checked the Examples section of QT (currently using version 5.2) and all the examples use triangle images, and there are no dotted lines showing the hierarchy. Does anyone knows where can I get sample code with "+" and "-"? I would not like to reinvent the wheel and code what already has been done thousand of times.
This is the picture of how exactly I want my tree to look like:
http://qt.developpez.com/doc/4.6/images/simpletreemodel-example.png

TIA

wysota
24th January 2015, 15:49
It's a matter of widget style used and not a matter of code. If you want, you can of course draw the nodes and branches the way you want by subclassing QTreeView and reimplementing relevant virtual methods.

nuliknol
24th January 2015, 16:50
It's a matter of widget style used and not a matter of code. If you want, you can of course draw the nodes and branches the way you want by subclassing QTreeView and reimplementing relevant virtual methods.

thanks!
well, I changed the stylesheets as in QT Reference says, but nothing happened. Should I have the images "branch-more.png" already installed by default ? Or do I have to download them? I searchd for *branch* file names inside QT installation directory and didn't find any. How can I debug what is happening when stylesheets don't work as expected?

this is the code I added:



deptree->setStyleSheet("QTreeView::branch:has-siblings:!adjoins-item { border-image: url(vline.png) 0; }");
deptree->setStyleSheet("QTreeView::branch:has-siblings:adjoins-item { border-image: url(branch-more.png) 0;}");
deptree->setStyleSheet("QTreeView::branch:!has-children:!has-siblings:adjoins-item { border-image: url(branch-end.png) 0;}");
deptree->setStyleSheet("QTreeView::branch:has-children:!has-siblings:closed,");
deptree->setStyleSheet("QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(branch-closed.png); }");
deptree->setStyleSheet("QTreeView::branch:open:has-children:!has-siblings,");
deptree->setStyleSheet("QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(branch-open.png); }");

wysota
24th January 2015, 22:38
I didn't mean stylesheets but widget styles. In Qt4 for example the plastique style will show the plus sign and dotted branches while some other style might not. In Qt5 for example the old Windows style shows pluses and dotted branches while the fusion style does not. And so on.