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. custom treeview / model
Forum Updated to NodeBB v4.3 + New Features

custom treeview / model

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 1.1k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    Nevez
    wrote on 5 Oct 2022, 14:39 last edited by
    #1

    9fc62eed-c0a3-492a-8ff3-07c679c28530-image.png

    Hello ,
    When the relevant parent is clicked as in the picture above, the information of the parent is opened as a separate node on the same line.
    When that node is clicked, the information of the node is opened in the same way.
    how should i do this? Can you give me an idea?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Oct 2022, 17:29 last edited by
      #2

      Hi,

      If I understand you correctly, you want to implement some sort of horizontal QTreeView ?

      From the looks of it, you will have to build your own QAbstractItemView.

      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
      1
      • N Offline
        N Offline
        Nevez
        wrote on 6 Oct 2022, 07:49 last edited by
        #3

        @SGaist said in custom treeview / model:

        From the looks of it, you will have to build your own QAbstractItemView.

        Thanks a lot for your answer. Sorry but I am really inexperienced with this treeview. How exactly do I need to change this horizontal line opening event compared to a normal Qtreeview?

        J 1 Reply Last reply 6 Oct 2022, 09:03
        0
        • N Nevez
          6 Oct 2022, 07:49

          @SGaist said in custom treeview / model:

          From the looks of it, you will have to build your own QAbstractItemView.

          Thanks a lot for your answer. Sorry but I am really inexperienced with this treeview. How exactly do I need to change this horizontal line opening event compared to a normal Qtreeview?

          J Offline
          J Offline
          JonB
          wrote on 6 Oct 2022, 09:03 last edited by JonB 10 Jun 2022, 09:04
          #4

          @Nevez
          What @SGaist is suggesting --- and it seemed to me that way too, plus he really know what he is talking about! --- is that a QTreeView really is not going to do your "horizontal" requirement. It is not going to do "create new columns on node expansion". QTreeView is designed to expnad nodes such that sub-nodes/children appear on a new row, and that is fundamental. Same if you look at a QTableView.

          Which means you are likely to need to "roll your own" tree view starting out from QAbstractItemView. Probably quite a bit of work --- think how much a QTreeView adds on top of this --- but not impossible.

          BTW, it is not evident to me what your "rules" are for horizontal vs vertical expansion. A cursory glance might indicate that your nodes are arranged vertically in rows while your leaves are expanded out horizontally in columns (and if more than one child, subsequent ones on a new row). However, that does not apply in your diagram to the Parent6 -> child1 -> child1:1 case. child1 is also a node (parent), so why should it not have been given its own row like the parents? Whatever your algorithm for this is you will have to code it.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Nevez
            wrote on 6 Oct 2022, 12:05 last edited by
            #5

            Thanks for the comments, I'll try them out.

            The rule will be determined by the data from the db.
            In other words, the data (nodes) in the same row in the db will be opened in the same horizontal (row) again.

            Example:
            table in my db:
            6db49903-a210-4fc2-b1ed-5b2a9e664320-image.png

            the view should be like this;

            jhon->wick->20->mercedes->black(black is last child and not parent).
            bella->chrown->33->>bmw->red(red is last child and not parent)

            J 1 Reply Last reply 6 Oct 2022, 12:10
            0
            • N Nevez
              6 Oct 2022, 12:05

              Thanks for the comments, I'll try them out.

              The rule will be determined by the data from the db.
              In other words, the data (nodes) in the same row in the db will be opened in the same horizontal (row) again.

              Example:
              table in my db:
              6db49903-a210-4fc2-b1ed-5b2a9e664320-image.png

              the view should be like this;

              jhon->wick->20->mercedes->black(black is last child and not parent).
              bella->chrown->33->>bmw->red(red is last child and not parent)

              J Offline
              J Offline
              JonB
              wrote on 6 Oct 2022, 12:10 last edited by
              #6

              @Nevez
              OK, but this is rather different from your first diagram. For example, it is not clear where 2 rows with child1 and child2 would come from....

              Your table is just straight rows with columns. There is no "tree structure" here. If this is all you want you might be able to do with just a straight QTableView, where each individual column in each row (i.e. each cell) is allocated to the table view but is initially hidden. Then when the user does some sort of "click to expand" that causes the column in row (i.e. cell) to now show its content.

              That would probably be a lot easier then having to write a lot of stuff yourself. But whether it's enough for what you really want I cannot say.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Nevez
                wrote on 6 Oct 2022, 12:16 last edited by Nevez 10 Jun 2022, 12:17
                #7

                sorry, I missed one more detail while telling you.
                The View also needs to do a grouping. For example, if there are 4 rows named John in the db, it should look like this;
                f5c66e59-75a5-4d10-a586-cb6a7cfaea0f-image.png
                for that i guess i will have to subclass the QAbstractItemView?

                J 1 Reply Last reply 6 Oct 2022, 12:28
                0
                • N Nevez
                  6 Oct 2022, 12:16

                  sorry, I missed one more detail while telling you.
                  The View also needs to do a grouping. For example, if there are 4 rows named John in the db, it should look like this;
                  f5c66e59-75a5-4d10-a586-cb6a7cfaea0f-image.png
                  for that i guess i will have to subclass the QAbstractItemView?

                  J Offline
                  J Offline
                  JonB
                  wrote on 6 Oct 2022, 12:28 last edited by
                  #8

                  @Nevez
                  Certainly you would get the best "effect" by subclassing QAbstractItemView and doing your work, because that is the most flexible. All the other views are derived from that, so by definition you can do anything they do, plus more. But the question is how much work that is: if you can leverage an existing table or tree view that saves you work.

                  I'm not sure a QTreeView would work for you, though it would be nice if it did. Again, so far I could more or less do what you just showed in a QTableView: the rows would be sorted by first name, then by last name, .... Given the same value in first column (John) you want to display that cell only the first row, then show it blank in all subsequent, consecutive rows where value is the same. And similarly on second column if you have multiple, adjacent rows for John followed by Wick.

                  I still think you're going to have to do a bit of work, to include the "click to reveal subsequent columns". Honestly I'm not sure you will know what you can achieve till you play with trying to do something...

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    Nevez
                    wrote on 6 Oct 2022, 14:24 last edited by
                    #9

                    thank you so much. I'm going to write some code about these

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 6 Oct 2022, 18:36 last edited by
                      #10

                      One important thing: you should build a proxy model that packs the data the way you want it. It's not the role of the view to rearrange data for painting.

                      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
                      1
                      • N Offline
                        N Offline
                        Nevez
                        wrote on 7 Oct 2022, 07:39 last edited by
                        #11

                        @SGaist said in custom treeview / model:

                        Verileri boyama için yeniden düzenlemek görünümün rolü değildir.

                        thanks, but I don't have a need for painting at the moment.
                        did you say that because of the last photo i posted?

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 7 Oct 2022, 19:02 last edited by
                          #12

                          No, globally. You start from table based data to finish with a three like representation. Hence, use a model to have your data structured the way you need it.

                          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

                          1/12

                          5 Oct 2022, 14:39

                          • Login

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