Results 1 to 5 of 5

Thread: Need to remove root node from QTreeView

  1. #1
    Join Date
    Apr 2014
    Posts
    7
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Need to remove root node from QTreeView

    Hi
    I'm new to QT and I'm trying to implement a TreeView from a QDomNode created manually. The problem I'm facing is that the resulting node has the following structure:
    root -->
    AA
    BB
    CC

    And of course that when setting the model in QTreeView I have the same structure, but what I need is to show in the QTreeView the 2 level:

    AA
    BB
    CC

    I had been searching in the forum for some ideas but I must say that I didn't found any...

    Is there any way to achieve this?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Need to remove root node from QTreeView


  3. #3
    Join Date
    Apr 2014
    Posts
    7
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Need to remove root node from QTreeView

    Thank you for the replay!

    I tried using these 2 functions but I don't get the desired result! The problem with setRootIndex is that if I use it like this:
    QModelIndex parentIndex = myModel->index(0,0);
    QModelIndex newIndex = myModel->index(0,0, parentIndex);
    myTree->setRootIndex(newIndex);

    I actually get the childs of AA ! not even the AA-parent is shown!!!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Need to remove root node from QTreeView

    Looks like you are going down one level too much.
    Initially the root index is QModelIndex(), you want index(0, 0), but you are setting index(0, 0, index(0, 0)

    Cheers,
    _

  5. #5
    Join Date
    Apr 2014
    Posts
    7
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Need to remove root node from QTreeView

    THANK YOU!!!!!
    You were right: myTree->setRootIndex( myModel->index(0,0));
    did the trick and now I have the desired structure in my view:
    AA
    BB
    CC

Similar Threads

  1. QTreeWidget set invisible root node?
    By Braf in forum Qt Programming
    Replies: 2
    Last Post: 10th February 2013, 02:03
  2. Remove node in XML file
    By pinjul in forum Newbie
    Replies: 11
    Last Post: 7th February 2013, 10:14
  3. How to create root node inQDirModel
    By deepak in forum Qt Programming
    Replies: 1
    Last Post: 29th August 2012, 07:03
  4. customize the root node of a treeview
    By billconan in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 08:06
  5. remove node in xml file
    By mattia in forum Newbie
    Replies: 1
    Last Post: 6th March 2008, 13:25

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.