Results 1 to 4 of 4

Thread: Tree sample code

  1. #1
    Join Date
    Apr 2014
    Posts
    53
    Thanks
    9

    Default Tree sample code

    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/ima...el-example.png

    TIA

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Tree sample code

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


  3. #3
    Join Date
    Apr 2014
    Posts
    53
    Thanks
    9

    Default Re: Tree sample code

    Quote Originally Posted by wysota View Post
    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:

    Qt Code:
    1. deptree->setStyleSheet("QTreeView::branch:has-siblings:!adjoins-item { border-image: url(vline.png) 0; }");
    2. deptree->setStyleSheet("QTreeView::branch:has-siblings:adjoins-item { border-image: url(branch-more.png) 0;}");
    3. deptree->setStyleSheet("QTreeView::branch:!has-children:!has-siblings:adjoins-item { border-image: url(branch-end.png) 0;}");
    4. deptree->setStyleSheet("QTreeView::branch:has-children:!has-siblings:closed,");
    5. deptree->setStyleSheet("QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(branch-closed.png); }");
    6. deptree->setStyleSheet("QTreeView::branch:open:has-children:!has-siblings,");
    7. deptree->setStyleSheet("QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(branch-open.png); }");
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Tree sample code

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


Similar Threads

  1. QUdpSocket sample code
    By alimooghashang in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2013, 21:59
  2. Adding a small tree to an existing tree in QTreeview.
    By salcin in forum Qt Programming
    Replies: 0
    Last Post: 25th September 2013, 18:27
  3. Qt video gui sample code
    By sanda199 in forum Newbie
    Replies: 5
    Last Post: 24th January 2013, 15:39
  4. Sample code to use QTreeWidget and QStackWidget
    By Jeff100 in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2010, 09:05
  5. Replies: 4
    Last Post: 18th November 2010, 14:00

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.