Results 1 to 5 of 5

Thread: Need advice regarding hierarchy view

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Need advice regarding hierarchy view

    Hi,

    I need to implement a widget that shows a hierarchy in the manner shown in the attached image.
    Those of you who know, it is very similar to the way that KProfiler shows the profiling graph.
    My question is, which base class should I use?
    In a way its exactly like a treeview, only the graphical representation is different (and there is no way to collapse/ expand), so I am thinking to subclass QAbstractItemView, but would like to hear (read) your opinions, may be you know a better class, or a better way.

    Thanks in advance.
    Attached Images Attached Images
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Need advice regarding hierarchy view

    depends:
    * would you like (or do you have) to interface to a QAbstractItemModel? a (bit of a) problem. QGraphicsView does not work with models out of the box; the QAbstractItemViews present don't do what you want.
    * you could implement a custom view

    no model needed:
    * do you want to interact with that hierarchy? take a look at QGraphicsView
    * just a read-only view of data that does not change anymore after displaying? then a simple QWidget with a custom paint() implementation might be enough

    So, tell us more about your requirements, please.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Need advice regarding hierarchy view

    depends:
    * would you like (or do you have) to interface to a QAbstractItemModel?
    Now that you asked, yes I do.
    Namely, I want to be able to receive a model, say, a model of a tree view, and display it in the way seen in the attached image (previous post).
    This alone probably will force me to use/derive QAbstractItemModel.
    a (bit of a) problem. QGraphicsView does not work with models out of the box;
    No, it wont be a QGraphicsView thing, just "plain" widgets.
    All though, now that I think of it, I need to weigh the advantages/disadvantages of QGraphicsView for this.
    the QAbstractItemViews present don't do what you want.
    There is no Qt class that is doing what I want, but I am looking for base class that will fit the best.
    As far as I see it, my widget and treeview only differ in the graphical presentation, and since QTreeView is derived from QAbstractItemModel, I thought it might be good for me too.
    * you could implement a custom view
    This is certain, but I am looking for good base class to manage my data

    no model needed:
    * do you want to interact with that hierarchy? take a look at QGraphicsView
    I will, but I have the feeling it is an over kill for what I need, but I'll see.
    * just a read-only view of data that does not change anymore after displaying? then a simple QWidget with a custom paint() implementation might be enough
    No, this will not be enough in my case, since I have real objects and drag/drop, and doing all of that in custom painting is not the way.
    So, tell us more about your requirements, please.
    Well actually you helped quite a bit with your suggestion and questions.
    What I really needed was a to push to "jog" my gray cells a bit :-)

    Thanks.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need advice regarding hierarchy view

    Hi Dani,

    I would go for a custom view. You'll have problems with defining/using visualRect() and working with selections as different items don't occupy disjoint rectangles so the problem is how to implement indexAt() - I guess the most trivial approach is to return the deepest item colliding with a point. If you decide what's best for you, the rest should be easy.

    An alternative would be to use graphics view as suggested. The advantage is that it is easy to group items this way using parent-child relationship and the fact that child items are always in front of their parents, so you'd always pick the deepest item out of the box without any additional effort. Unfortunately apart from that and the fact that GV allows to operate on graphics easily I don't see any advantages of using graphics view. And a certain disadvantage is that it is not trivial to display the same hierarchy using a different view (like a real tree or a table). With the model-view approach, you'd have that for free.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Need advice regarding hierarchy view

    Thanks for the input guys.
    I will have to see what I do, I think I can't get away from experimenting.

    Cheers.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Graphics View - Scene & Item hierarchy
    By mooreaa in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2008, 23:49
  2. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50

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
  •  
Qt is a trademark of The Qt Company.