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. Draw order of QGraphicsItems
Forum Updated to NodeBB v4.3 + New Features

Draw order of QGraphicsItems

Scheduled Pinned Locked Moved Solved General and Desktop
11 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.
  • L Offline
    L Offline
    leonardoMB
    wrote on last edited by leonardoMB
    #1

    I would like to understand and solve one problem that involve "uncle/cousin" relationship between items. I Have a button class and two instances of it, say it A and B. The button class inherits from QGraphicsItem and has a method that is QGraphicsRectItem, I use it to represent a tooltip.

    The problem is: when I draw the buttons A and B next to the other, the tooltip of A is drawn behind B, but I want that any tooltip is always drawn on top of any object of button class.

    JonBJ 1 Reply Last reply
    0
    • JonBJ JonB

      @leonardoMB
      OK, we are back to: at any one instant, only one tooltip is visible on the view.

      Originally you wrote:

      The button class inherits from QGraphicsItem and has a method that is QGraphicsRectItem, I use it to represent a tooltip.

      You didn't mean a method, you turn out to mean a child, right? That's vitally important.

      So you have you tooltip rect items as children of your gfx items. Then you want button A to be behind button B, but button A's tooltip to be in front of button B, right?

      Not certain, but I don't think parent/child allows this. I suspect A's child tooltip will always be directly on top of A, wherever that is the z-order. Though you could still try with toolTipItem.setZValue(VERY_LARGE_NUMBER) to see.

      You could try not parent-child but QGraphicsItemGroup with separate z-orders. But again I think it won't do what you want.

      Instead of parent/child gfx items, you could create a non-parented tooltip rectangle item with a high z-order value and using the rectangle's coordinates to place it at the instant you want to show it. That would place it at the top of all other items.

      Finally if that QGraphicsItem::setToolTip() can be used to do what you want to achieve with the z-order it would be a lot simpler!

      L Offline
      L Offline
      leonardoMB
      wrote on last edited by
      #10

      @JonB Just to give a follow up: I could solve the problem by not parenting the attribute as you suggested, so both became toplevel. Based on that, I only had to guarantee that the tooltip object would have a zValue always greater than any button zValue

      JonBJ 1 Reply Last reply
      0
      • L leonardoMB

        I would like to understand and solve one problem that involve "uncle/cousin" relationship between items. I Have a button class and two instances of it, say it A and B. The button class inherits from QGraphicsItem and has a method that is QGraphicsRectItem, I use it to represent a tooltip.

        The problem is: when I draw the buttons A and B next to the other, the tooltip of A is drawn behind B, but I want that any tooltip is always drawn on top of any object of button class.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @leonardoMB
        https://doc.qt.io/qt-5/qgraphicsitem.html#painting

        Items are painted by the view, starting with the parent items and then drawing children, in ascending stacking order. You can set an item's stacking order by calling setZValue(), and test it by calling zValue(), where items with low z-values are painted before items with high z-values. Stacking order applies to sibling items; parents are always drawn before their children.

        and has a method that is QGraphicsRectItem, I use it to represent a tooltip

        void QGraphicsItem::setToolTip(const QString &toolTip)?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leonardoMB
          wrote on last edited by leonardoMB
          #3

          Hi @JonB. The second tip may help, I didn't pay attention to this tooltip method
          About the painting order, I have read the Qt text, but didn't find a way to solve the case Above, I mean, I could work with the zValues, but I want something more robust, but not so complicated. In a case where I would have 1000 buttons in any order, for example, I still would want the tooltip to be drawn on top of every button

          JonBJ 1 Reply Last reply
          0
          • L leonardoMB

            Hi @JonB. The second tip may help, I didn't pay attention to this tooltip method
            About the painting order, I have read the Qt text, but didn't find a way to solve the case Above, I mean, I could work with the zValues, but I want something more robust, but not so complicated. In a case where I would have 1000 buttons in any order, for example, I still would want the tooltip to be drawn on top of every button

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @leonardoMB said in Draw order of QGraphicsItems:

            Above, I mean, I could work with the zValues, but I want something more robust, but not so complicated. In a case where I would have 1000 buttons in any order, for example, I still would want the tooltip to be drawn on top of every button

            What is not robust, or complicated, about toolTipItem.setZValue(VERY_LARGE_NUMBER)?

            To confirm: one single tooltip item to be drawn up-front no matter how many buttons/other items, right, not one tooltip per item?

            L 1 Reply Last reply
            0
            • JonBJ JonB

              @leonardoMB said in Draw order of QGraphicsItems:

              Above, I mean, I could work with the zValues, but I want something more robust, but not so complicated. In a case where I would have 1000 buttons in any order, for example, I still would want the tooltip to be drawn on top of every button

              What is not robust, or complicated, about toolTipItem.setZValue(VERY_LARGE_NUMBER)?

              To confirm: one single tooltip item to be drawn up-front no matter how many buttons/other items, right, not one tooltip per item?

              L Offline
              L Offline
              leonardoMB
              wrote on last edited by
              #5

              @JonB one tooltip per button, so "n" buttons have "n" tooltips. Each button with its own tooltip.

              toolTipItem.setZValue(VERY_LARGE_NUMBER)
              

              But How can I use Zvalue? the documentation says it must be siblings, but the tooltip is "cousin" of the others buttons

              JonBJ 1 Reply Last reply
              0
              • L leonardoMB

                @JonB one tooltip per button, so "n" buttons have "n" tooltips. Each button with its own tooltip.

                toolTipItem.setZValue(VERY_LARGE_NUMBER)
                

                But How can I use Zvalue? the documentation says it must be siblings, but the tooltip is "cousin" of the others buttons

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @leonardoMB said in Draw order of QGraphicsItems:

                one tooltip per button, so "n" buttons have "n" tooltips. Each button with its own tooltip.

                That changes everything. It was not what I understood, I do now.

                Are these "tooltip windows" to be present (visible) all the time their corresponding item is visible? They are permanently present & visible, e.g. not like a tooltip which only appears when you hover over an item, and not only one item in the whole view displays its tooltip at a time?

                L 1 Reply Last reply
                0
                • JonBJ JonB

                  @leonardoMB said in Draw order of QGraphicsItems:

                  one tooltip per button, so "n" buttons have "n" tooltips. Each button with its own tooltip.

                  That changes everything. It was not what I understood, I do now.

                  Are these "tooltip windows" to be present (visible) all the time their corresponding item is visible? They are permanently present & visible, e.g. not like a tooltip which only appears when you hover over an item, and not only one item in the whole view displays its tooltip at a time?

                  L Offline
                  L Offline
                  leonardoMB
                  wrote on last edited by
                  #7

                  @JonB I tryed to be succint as possible to not bother you, but it lacked information.
                  They are implemented with the HoverEnterEvent, so the tooltip just appear when I hover a button.

                  JonBJ 1 Reply Last reply
                  0
                  • L leonardoMB

                    @JonB I tryed to be succint as possible to not bother you, but it lacked information.
                    They are implemented with the HoverEnterEvent, so the tooltip just appear when I hover a button.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #8

                    @leonardoMB
                    OK, we are back to: at any one instant, only one tooltip is visible on the view.

                    Originally you wrote:

                    The button class inherits from QGraphicsItem and has a method that is QGraphicsRectItem, I use it to represent a tooltip.

                    You didn't mean a method, you turn out to mean a child, right? That's vitally important.

                    So you have you tooltip rect items as children of your gfx items. Then you want button A to be behind button B, but button A's tooltip to be in front of button B, right?

                    Not certain, but I don't think parent/child allows this. I suspect A's child tooltip will always be directly on top of A, wherever that is the z-order. Though you could still try with toolTipItem.setZValue(VERY_LARGE_NUMBER) to see.

                    You could try not parent-child but QGraphicsItemGroup with separate z-orders. But again I think it won't do what you want.

                    Instead of parent/child gfx items, you could create a non-parented tooltip rectangle item with a high z-order value and using the rectangle's coordinates to place it at the instant you want to show it. That would place it at the top of all other items.

                    Finally if that QGraphicsItem::setToolTip() can be used to do what you want to achieve with the z-order it would be a lot simpler!

                    L 1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      leonardoMB
                      wrote on last edited by
                      #9

                      I did mean attribute, but I misswritten, so you are right: I mean a child. Exactly:
                      I want button A to be behind button B, but button A's tooltip to be in front of button B.
                      I will try some of your ideas, unfortunately QGraphicsItem::setToolTip() cannot be implemented right now. Thanks in advance

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @leonardoMB
                        OK, we are back to: at any one instant, only one tooltip is visible on the view.

                        Originally you wrote:

                        The button class inherits from QGraphicsItem and has a method that is QGraphicsRectItem, I use it to represent a tooltip.

                        You didn't mean a method, you turn out to mean a child, right? That's vitally important.

                        So you have you tooltip rect items as children of your gfx items. Then you want button A to be behind button B, but button A's tooltip to be in front of button B, right?

                        Not certain, but I don't think parent/child allows this. I suspect A's child tooltip will always be directly on top of A, wherever that is the z-order. Though you could still try with toolTipItem.setZValue(VERY_LARGE_NUMBER) to see.

                        You could try not parent-child but QGraphicsItemGroup with separate z-orders. But again I think it won't do what you want.

                        Instead of parent/child gfx items, you could create a non-parented tooltip rectangle item with a high z-order value and using the rectangle's coordinates to place it at the instant you want to show it. That would place it at the top of all other items.

                        Finally if that QGraphicsItem::setToolTip() can be used to do what you want to achieve with the z-order it would be a lot simpler!

                        L Offline
                        L Offline
                        leonardoMB
                        wrote on last edited by
                        #10

                        @JonB Just to give a follow up: I could solve the problem by not parenting the attribute as you suggested, so both became toplevel. Based on that, I only had to guarantee that the tooltip object would have a zValue always greater than any button zValue

                        JonBJ 1 Reply Last reply
                        0
                        • L leonardoMB

                          @JonB Just to give a follow up: I could solve the problem by not parenting the attribute as you suggested, so both became toplevel. Based on that, I only had to guarantee that the tooltip object would have a zValue always greater than any button zValue

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #11

                          @leonardoMB
                          Indeed exactly as I suggested might be the simplest possibility. The only thing is that you have manage showing it at the correct place relative to your rectangle.

                          It is interesting that you have ended up accepting to use z-value to achieve on-top. When you said originally

                          I could work with the zValues, but I want something more robust, but not so complicated.

                          I take it you decided z-value is not flaky/complicated after all :)

                          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