Results 1 to 7 of 7

Thread: QTreeView: expand(), expandAll(), setExpanded() not work

  1. #1
    Join Date
    Jul 2014
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3

    Default QTreeView: expand(), expandAll(), setExpanded() not work

    Hi,

    When I create a QTreeView with QStandardItemModel, I could see the QStandardItems in the tree view.
    I try to expand some of them by expand() or setExpanded(), but it doesn't work.
    Then I try to expand all by expandAll(), it doesn't work also.
    I can see isExpanded() return TRUE after the calling above.
    It should be something wrong with my QTreeView. Any idea? Thanks.

  2. #2
    Join Date
    Jul 2014
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3

    Default Re: QTreeView: expand(), expandAll(), setExpanded() not work

    Complement:
    I found when I do some GUI action later, the expansion works.
    Now the question is why it couldn't work immediately.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,342
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: QTreeView: expand(), expandAll(), setExpanded() not work

    expand() and expandAll() are slots. setExpanded() probably invokes one of these slots. It probably doesn't work because your code doesn't return to the Qt event loop so it can handle the calls to the slots. The fact that it doesn't happen until you "do some GUI action later" is a big clue.

    The trick is to change your app so it isn't compute bound - a major cause of GUI unresponsiveness.

  4. The following user says thank you to d_stranz for this useful post:

    jasonhxs (31st July 2014)

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

    Default Re: QTreeView: expand(), expandAll(), setExpanded() not work

    Quote Originally Posted by jasonhxs View Post
    Complement:
    I found when I do some GUI action later, the expansion works.
    Now the question is why it couldn't work immediately.
    Please post a minimal compilable example reproducing the problem.
    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.


  6. #5
    Join Date
    Jul 2014
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3

    Default Re: QTreeView: expand(), expandAll(), setExpanded() not work

    It is hard to reproduce it, since my code is a little more.
    Any suggestion to make it work immediately, like calling some APIs.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTreeView: expand(), expandAll(), setExpanded() not work

    Quote Originally Posted by jasonhxs View Post
    It is hard to reproduce it, since my code is a little more.
    Any suggestion to make it work immediately, like calling some APIs.
    If you can't reproduce the problem with a small example then it is likely that the problem originates in your own code and if so, then without knowing where the problem lies it is hardly possible to suggest a solution. I suggest you spend 20 minutes trying to assemble a minimal compilable example reproducing the problem.
    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.


  8. #7
    Join Date
    Jul 2014
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3

    Default Re: QTreeView: expand(), expandAll(), setExpanded() not work

    Hi all,

    I found the root cause, it is because I called model->clear() in somewhere, it will impact the data that was inserted in model.
    After I remove it, the expanison works well. Thanks all~

Similar Threads

  1. Replies: 2
    Last Post: 31st July 2013, 18:06
  2. QTreeView expand and collapse
    By Qiieha in forum Qt Programming
    Replies: 4
    Last Post: 9th October 2012, 13:57
  3. QTreeView -- only expand active (clicked) row
    By mardi in forum Qt Programming
    Replies: 6
    Last Post: 5th September 2012, 10:41
  4. QTreeView: expandAll() and expandToDepth(int) not working
    By papillon in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2011, 00:30
  5. QTreeView expand signals
    By Vidar Bøe in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2008, 10:47

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
  •  
Qt is a trademark of The Qt Company.