Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Factory for tree view
Qt 6.11 is out! See what's new in the release blog

Factory for tree view

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.0k 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.
  • O Offline
    O Offline
    omnitect
    wrote on last edited by
    #1

    I currently have a tree model implemented in C++ as an extension of QAbstractItemModel and now I am trying to make a custom view for it. One step that I can see in the process is creating a factory to dynamically figure out which component to use, whether it be a recursive Layout object, or a view specification. Is there any prior work that I could look to for something like this?

    DiracsbracketD 1 Reply Last reply
    0
    • O omnitect

      I currently have a tree model implemented in C++ as an extension of QAbstractItemModel and now I am trying to make a custom view for it. One step that I can see in the process is creating a factory to dynamically figure out which component to use, whether it be a recursive Layout object, or a view specification. Is there any prior work that I could look to for something like this?

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      @omnitect
      Do you mean something like a Component + Loader combination as in:
      https://forum.qt.io/topic/93180/updating-qabstractitemmodel-model-is-null-although-begin-endresetmodel-have-been-called/4
      or possibly simply the loader part of it?

      1 Reply Last reply
      0
      • O Offline
        O Offline
        omnitect
        wrote on last edited by omnitect
        #3

        That looks about right, but also a bit ugly. I'm going to have a lot of possible classes (one for each possible visualization of the data), so it would be better to have a more succinct registration processes that switch case in qml. I'm hoping there is a way to do it in the c++ world. Also, the component needs to be able to instantiate itself recursively and I'm not sure if that one allows for it.

        O DiracsbracketD 2 Replies Last reply
        0
        • O omnitect

          That looks about right, but also a bit ugly. I'm going to have a lot of possible classes (one for each possible visualization of the data), so it would be better to have a more succinct registration processes that switch case in qml. I'm hoping there is a way to do it in the c++ world. Also, the component needs to be able to instantiate itself recursively and I'm not sure if that one allows for it.

          O Offline
          O Offline
          omnitect
          wrote on last edited by
          #4

          @Diracsbracket Or, since the tree model just provides positioning for real painted items, I wouldn't need the factory to be able to recursively call itself, but I would still like a more elegant way of loading in the elements, unlike in the factory example you gave.

          1 Reply Last reply
          0
          • O omnitect

            That looks about right, but also a bit ugly. I'm going to have a lot of possible classes (one for each possible visualization of the data), so it would be better to have a more succinct registration processes that switch case in qml. I'm hoping there is a way to do it in the c++ world. Also, the component needs to be able to instantiate itself recursively and I'm not sure if that one allows for it.

            DiracsbracketD Offline
            DiracsbracketD Offline
            Diracsbracket
            wrote on last edited by
            #5

            @omnitect
            The Loader's source property takes a URL, so it is conceivable that you put all those URL's in a list, and retrieve the desired URL using its index?

            As for the recursive instantiation, it seems it is not allowed in QML?
            https://bugreports.qt.io/browse/QTBUG-25439
            Now, it no longer crashes, but generates the following error:

            QQmlComponent: Component creation is recursing - aborting

            1 Reply Last reply
            0
            • O Offline
              O Offline
              omnitect
              wrote on last edited by
              #6

              @Diracsbracket
              Ok, thanks. So I'll just compute the space each leaf would go into and then use a factory to instantiate the components used. I think I can actually do it from C++ more easily, because I can either create from referencing a resource or by instantiating one of my custom visualization classes.

              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