Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating Custom Hierarchy with QTreeView/QAbstractItemModel
QtWS25 Last Chance

Creating Custom Hierarchy with QTreeView/QAbstractItemModel

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KizzangTravis
    wrote on last edited by
    #1

    Hey all,

    I've started using Qt, and this is my first post here! I'm working on an OpenGL-based animation application for signed-distance field fonts, and I need to create a hierarchy model that's got 3 levels to it: font, strings and animations. The top level represents a list of loaded type faces. Each type face item has its own list of "strings" (that's the mid-level to my hierarchy). Each "string" has a list of "animations" to it (that's the 3rd and bottom level). This isn't so much like a scene graph hierarchy where nodes' parent/child relationships can change --it's more like Qt Creator's own Project dock's hierarchy with projects at the top level with folder filters beneath them followed by files.

    Do I have to make 3 QAbstractItemModel subclasses for my Fonts, Strings and Animations? Also, do the model(s) responsible for holding the data needed for my Fonts, Strings and Animations, or do I have separate classes for that, then feed that to my model? I've been going through the docs for QTreeView and QAbstractItemModel. On top of that, I've found a few things regarding custom implementations, like this tutorial here.

    Also, what is the point of QAbstractItemModel's "role"? From what I've gathered, one of the roles in can have is "Display", which should be used to represent data that's to be displayed to the user. I'm not too sure what other roles there are, and how Qt enforces them outside of explicit logic that's up to the programmer when making the subclass.

    Also, are there any good resources that have different examples on how to create custom views for QTreeView?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      The other roles are used already by the views e.g. the decoration role to show an icon, the edit role to get the data to edit (matches usually the display role but might be different) etc. It's indeed the developer roles to provide useful data for the roles that make sense for its model, other wise either return an invalid QVariant or the base class value.

      You also have the Simple Tree Model example to help you get started.

      If you already have a data structure for your Font/String/Animation combo, you can use QAbstractItemModel on top of it.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved