Results 1 to 4 of 4

Thread: QTreeView expansion after model reset

  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QTreeView expansion after model reset

    I have a QTreeView that displays the contents of a custom QAbstractItemModel-based class. The custom model wraps a data structure that can be updated when the app recomputes results. When this happens, the model calls beginResetModel() / endResetModel(), which results in a modelReset() signal. All is fine with this part.

    When the tree view receives notification of an updated model, I want to expand the root item to display all of its top-level children. So, I have made a connection between the model's modelReset() signal and a slot in the widget that contains the QTreeView. In this slot, I call QTreeView::expandToDepth( 1 ). Unfortunately, it appears that this slot is being invoked before the tree view updates itself, because I can see the view's contents disappear and then reappear (unexpanded) after leaving the slot. (I have replaced the expandToDepth() call with expandAll() with the same result).

    Is there a way I can determine that the tree view has finished its internal update after a model reset so I can expand the root node?

  2. #2
    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: QTreeView expansion after model reset

    I would start a timer with a tiny interval upon receiving modelReset() and then expand the tree when it fires.
    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
    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: QTreeView expansion after model reset

    Are you connecting after setting the model on the view?

    Otherwise you will get the reset signal before the view does.

    Cheers,
    _

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

    d_stranz (4th December 2014)

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView expansion after model reset [SOLVED]

    Are you connecting after setting the model on the view?

    Otherwise you will get the reset signal before the view does.
    You nailed it. I had thought about the connection order, but I guess I assumed I was doing it in the right order. Reversing the order fixed it.
    Last edited by d_stranz; 4th December 2014 at 01:10.

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

    neuronet (20th February 2015)

Similar Threads

  1. QTreeView model
    By ComaWhite in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2012, 23:56
  2. Replies: 5
    Last Post: 10th March 2011, 21:06
  3. QTreeview/Model and signals
    By mgb_qt in forum Qt Programming
    Replies: 3
    Last Post: 31st March 2010, 16:53
  4. Replies: 1
    Last Post: 9th February 2010, 13:11
  5. Replies: 3
    Last Post: 31st March 2008, 22:23

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.