Results 1 to 4 of 4

Thread: [QT4] QTreeView and expandable nodes

  1. #1
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default [QT4] QTreeView and expandable nodes

    Is it possible to make a node marked as "expandable" if the model does not (yet) have any data loaded on that node?

    What I'd like to do is set up a signal/slot connection to the view's expand() signal to tell the model to look up data for a given node.

    I'd like to do this because looking up all the data at once takes several seconds, so taking in pieces of the data as needed should take significantly less time.

    Currently, if there's no data under a node, there is no '+' symbol to click on. Can this behaviour be changed?
    Life without passion is death in disguise

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QT4] QTreeView and expandable nodes

    ugly workaround but should work : create an empty model item prevent from doing a real expanding while no other item is added and remove it when another item is added (you've got to subclass QTreeView I guess...)
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: [QT4] QTreeView and expandable nodes

    Yeah... currently, what I have is that there's a "placeholder" model item that's blank. When expanded, the model gets the expand signal. If it detects the placeholder, it removes it and inserts all the appropriate data. It only inserts the placeholder if it detects that a given node would have at least one element, so I don't get expandable nodes when there's no data under them.

    I didn't have to subclass the view (thankfully). I just connected the view's expanded signal to my model's [/b]slotNodeExpanded[/b] slot.

    It is kinda ugly, but at the moment it gets the job done properly. I was hoping to find a more elegant solution .
    Life without passion is death in disguise

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

    Default Re: [QT4] QTreeView and expandable nodes

    You could subclass the delegate and introduce a custom role which would say if an "expand indicator" should be drawn, but unfortunately the tree view is the object responsible for drawing them, so it's obviously a limitation of interview.

    In short words -- you can't do it "the right way".

Similar Threads

  1. QTreeView and expandable items
    By SiLiZiUMM in forum Qt Programming
    Replies: 6
    Last Post: 29th April 2008, 13:21

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.