Results 1 to 2 of 2

Thread: QAbstractItemModel for QTreeView with separate data

  1. #1
    Join Date
    Jun 2016
    Posts
    1

    Default QAbstractItemModel for QTreeView with separate data

    Hello,
    I have a problem implementing a QAbstractItemModel derived class. I might be missing fundamental concepts and missusing the Model/View concept, but first of all here is the situation:
    The data is stored in a custom class. This data class is implemented completely independent from the view and the model and does not contain particular information about a certain tree structure. I now tried to implement the QAbstractItemModel in a way that it builds up the tree structure (basically in the parent and index function). I know how to build up the tree, given the data class and could describe it "with words". Tree relationships are for instance determined by the type of objects and the position of those in QLists that belong to the data class. In order to make this work, I have to somehow find out the type of the object that is referenced by the internal (void) pointer in a QModelIndex. I had to make some kind of virtual base class for those object because otherwise I was not able to find out the type (static/dynamic cast). Now I also want to have nodes in the TreeView that actually do not have any "real" data in the class. Those are used as categories/folders to structure things. The internal pointer of the corresponding QModelIndex could just point to some QString, but then I am not able to determine the type if I see this QModelIndex later on in the parent/index functions.
    I have the feeling that I am missing some fundamental conceptional thing here. Perhaps my describtion is good enough and some expert can enlighten me

    Best
    Clemens

  2. #2
    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: QAbstractItemModel for QTreeView with separate data

    What you can do is to build and actual tree structure in the model, with two types of nodes

    1) nodes that further point to data into your data structure
    2) nodes that are categories

    The interal point would then always be to such a node

    The first kind of node could also hold the information you need to distinguish between different types in your data class.

    Cheers,
    _

Similar Threads

  1. Replies: 7
    Last Post: 11th September 2014, 14:02
  2. Performance with QTreeView and QAbstractItemModel
    By Goug in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2011, 00:30
  3. QTreeView with QAbstractItemModel
    By Fletcher in forum Qt Programming
    Replies: 4
    Last Post: 10th December 2009, 23:02
  4. Creating a QAbstractItemModel for QTreeView
    By hbill in forum Qt Programming
    Replies: 13
    Last Post: 14th August 2008, 16:01
  5. Need help with QTreeView/QAbstractItemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th August 2006, 15:09

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.