Results 1 to 2 of 2

Thread: How to clear QTreeView derived from QAbstractItemModel

  1. #1
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question How to clear QTreeView derived from QAbstractItemModel

    Hi,

    I am using a QTreeview whose model class is derived from QAbstractItemModel. I have my model data in a QList, to populate the treeview. Now, on click of Cancel button, i want to clear all the items in the treeview (make it empty). QTreeview is not getting cleared just by clearing the QList model data.Not sure, how to use beginresetmodel,endresetmodel,etc . Please help me on this

  2. #2
    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: How to clear QTreeView derived from QAbstractItemModel

    In your custom model, in whatever method it is that you clear the QList, call beginResetModel() -before- you clear the list, then endResetModel() -after- you have cleared it. The tree view should automatically update itself once the method exits and control returns to the event loop.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 6th December 2012, 20:56
  2. Replies: 2
    Last Post: 12th May 2010, 14:32
  3. QTreeView with QAbstractItemModel
    By Fletcher in forum Qt Programming
    Replies: 4
    Last Post: 11th December 2009, 00:02
  4. Need help with QTreeView/QAbstractItemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th August 2006, 16:09
  5. How to clear All items on QTreeView ?
    By qintm in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2006, 12:39

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.