Results 1 to 5 of 5

Thread: QAbstractItemModel or QStandardItemModel

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

    Question QAbstractItemModel or QStandardItemModel

    Hi,

    I have a class with huge number of data members in it out of which few members should be shown up as Tree format and other few members should be used as table format. I am sure that I should be going for Model-View Architecture (QTreeView and QTableView). My question here is which model should I prefer? A class subclassing QAbstractItemModel or a class subclassing QStandardItemModel ? What is the difference and when /why I prefer over one another?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,294
    Thanks
    36
    Thanked 1,521 Times in 1,472 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemModel or QStandardItemModel

    QStandardItemModel is usually not being used as a base class.

    Its main purpose is to have a ready-to-go model that contains data rather than provides access to already existing data.
    E.g. when you have data that is just displayed but isn't needed elsewhere, then you can simply create QStandardItem objects with that data and use these to forma list, table or tree.

    Creating a custom model, e.g. a table based on QAbstractTableModel, is more work, but allows to access data that already exists in some form elsewhere.

    Sometimes the QStandardItemModel is also used as an intermediate step, as it is faster to get something to show up than implementing a custom model, especially tree models.

    Cheers,
    _

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

    Default Re: QAbstractItemModel or QStandardItemModel

    Do i really need to go for QStandardItemModel() for QTreeView? What if my data(to be shown in QTreeView) is large in number?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,294
    Thanks
    36
    Thanked 1,521 Times in 1,472 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemModel or QStandardItemModel

    Quote Originally Posted by chithara View Post
    Do i really need to go for QStandardItemModel() for QTreeView?
    Why would you need to do that?

    Quote Originally Posted by chithara View Post
    What if my data(to be shown in QTreeView) is large in number?
    Then you would most likely implement a custom tree model, deriving from QAbstractItemModel

    Cheers,
    _

  5. #5
    Join Date
    Jun 2018
    Location
    India
    Posts
    27
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QAbstractItemModel or QStandardItemModel

    Implemented own custom tree model from QAbstractItemModel (followed Qt example SimpleTreeModel)
    Thank you

Similar Threads

  1. QStandardItemModel
    By neda in forum Qt Quick
    Replies: 5
    Last Post: 1st May 2016, 12:58
  2. using QStandardItemModel
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 6th March 2011, 09:13
  3. QAbstractItemModel, QStandardItemModel
    By homerun4711 in forum Newbie
    Replies: 2
    Last Post: 16th December 2010, 09:18
  4. QStandardItemModel Help
    By frenk_castle in forum Newbie
    Replies: 1
    Last Post: 16th January 2010, 17:54
  5. QStandardItemModel limits
    By baray98 in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2008, 09:51

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.