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. Hide Rectangle Behind Transparent Rectangle

Hide Rectangle Behind Transparent Rectangle

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 431 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.
  • R Offline
    R Offline
    Redman
    wrote on 13 Feb 2025, 14:28 last edited by Redman
    #1

    Hi,

    I have a background image with some electrical components.
    The background image provides the gray and brown rectangle.
    Some of the components overlap on this background image.

    Now I am setting a border width on some rectangles I drew over these background rectangle components to visualize warnings and errors.

    fad7db94-1c9c-470d-8840-a002bc9c384f-image.png
    In this case everything is fine. But if we reverse that, and let the component which is behind the other one have an error/warning while the front one has none it looks like this. (Which is to be expected, since the color of the rectangle that encircles the brown rectangle is actually "transparent" so we can see the background image)

    76ec2fe4-a172-4f09-9bdd-64627db990e2-image.png

    Is there any way to achieve, that the component behind is actually really covered by the rectangle of the component in front but still let the brown part of the background image through? Like so:
    b260d8e1-88b4-47de-89f7-c5934fb83d96-image.png

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Feb 2025, 19:46 last edited by
      #2

      Hi,

      How are you doing the rendering ? Using QLabel ? Painting things yourself ? Using the graphics view framework ?

      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
      • J Offline
        J Offline
        jeremy_k
        wrote on 14 Feb 2025, 04:09 last edited by
        #3

        Based on the category, I'm presuming that the underlying graphic stack is Qt Quick.

        This looks like something that should be possible with a ShaderEffect or OpacityMask applied to the warning display item.

        The mask will need to know the geometry of the underlying shape that shouldn't be covered. For simple scenarios, I would think that it would be easier to break up the background into separate items and use Z-ordering.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        R 1 Reply Last reply 14 Feb 2025, 10:25
        1
        • J jeremy_k
          14 Feb 2025, 04:09

          Based on the category, I'm presuming that the underlying graphic stack is Qt Quick.

          This looks like something that should be possible with a ShaderEffect or OpacityMask applied to the warning display item.

          The mask will need to know the geometry of the underlying shape that shouldn't be covered. For simple scenarios, I would think that it would be easier to break up the background into separate items and use Z-ordering.

          R Offline
          R Offline
          Redman
          wrote on 14 Feb 2025, 10:25 last edited by Redman
          #4

          @jeremy_k While I understand your suggestion I do not think I am able to implement it.
          I have a factory inside qml that takes coordinate and dimensions of the rectangle which I want to overlay over the background. So these rectangles that overlap dont know of each others existense (they could, but whats the point of the factory and how do I approach this? The order in which the rectangles will be rendered can be changed etc etc). Since this background is prone to change (though, marginally) it is not feasable tomask the rectangle with lower z.

          Is there any way to mask the rectangle with higher z to accomplish this?

          Basically I have 3 layers.
          1 - background
          2 - low z rectangle
          3 - high z rectangle

          I want to mask 3, so 2 is not shown within mask 3 but 1 is shown. This seems kinda impossible without telling 2 what to do. Or am I wrong?

          J 1 Reply Last reply 15 Feb 2025, 07:03
          0
          • R Redman
            14 Feb 2025, 10:25

            @jeremy_k While I understand your suggestion I do not think I am able to implement it.
            I have a factory inside qml that takes coordinate and dimensions of the rectangle which I want to overlay over the background. So these rectangles that overlap dont know of each others existense (they could, but whats the point of the factory and how do I approach this? The order in which the rectangles will be rendered can be changed etc etc). Since this background is prone to change (though, marginally) it is not feasable tomask the rectangle with lower z.

            Is there any way to mask the rectangle with higher z to accomplish this?

            Basically I have 3 layers.
            1 - background
            2 - low z rectangle
            3 - high z rectangle

            I want to mask 3, so 2 is not shown within mask 3 but 1 is shown. This seems kinda impossible without telling 2 what to do. Or am I wrong?

            J Offline
            J Offline
            jeremy_k
            wrote on 15 Feb 2025, 07:03 last edited by
            #5

            @Redman said in Hide Rectangle Behind Transparent Rectangle:

            @jeremy_k While I understand your suggestion I do not think I am able to implement it.
            I have a factory inside qml that takes coordinate and dimensions of the rectangle which I want to overlay over the background. So these rectangles that overlap dont know of each others existense (they could, but whats the point of the factory and how do I approach this? The order in which the rectangles will be rendered can be changed etc etc). Since this background is prone to change (though, marginally) it is not feasable tomask the rectangle with lower z.

            Is there any way to mask the rectangle with higher z to accomplish this?

            Basically I have 3 layers.
            1 - background
            2 - low z rectangle
            3 - high z rectangle

            I want to mask 3, so 2 is not shown within mask 3 but 1 is shown. This seems kinda impossible without telling 2 what to do. Or am I wrong?

            "Telling 2 what to do" matches my first suggestion, altering the opacity of the appropriate section to make it transparent. Perhaps a window compositor type abstraction to apply the opacity mask fits better with the existing code.

            Another option to is have 3 replicate the portion of 1 that it covers, resulting in painting over the top of 2.

            Rectangle {
              id: bottom
              color: "red"
              Rectangle {
                width: bottom.width / 2
                height: bottom.height
                color: "green"
                Rectangle {
                  width: parent.width / 2
                  height: parent.height / 2
                  color: bottom.color
                }
              }
            }
            

            Depending on the source of the bottom layer, the top layer might use an Image, ShaderEffect, or something else entirely. A downside to this strategy is that everything that might be impacted must redraw its visible area, as opposed to calculating the impacted area and only redrawing there. This strategy also becomes more complicated if graphics from multiple layers need to be repeated.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            R 1 Reply Last reply 17 Feb 2025, 06:41
            0
            • J jeremy_k
              15 Feb 2025, 07:03

              @Redman said in Hide Rectangle Behind Transparent Rectangle:

              @jeremy_k While I understand your suggestion I do not think I am able to implement it.
              I have a factory inside qml that takes coordinate and dimensions of the rectangle which I want to overlay over the background. So these rectangles that overlap dont know of each others existense (they could, but whats the point of the factory and how do I approach this? The order in which the rectangles will be rendered can be changed etc etc). Since this background is prone to change (though, marginally) it is not feasable tomask the rectangle with lower z.

              Is there any way to mask the rectangle with higher z to accomplish this?

              Basically I have 3 layers.
              1 - background
              2 - low z rectangle
              3 - high z rectangle

              I want to mask 3, so 2 is not shown within mask 3 but 1 is shown. This seems kinda impossible without telling 2 what to do. Or am I wrong?

              "Telling 2 what to do" matches my first suggestion, altering the opacity of the appropriate section to make it transparent. Perhaps a window compositor type abstraction to apply the opacity mask fits better with the existing code.

              Another option to is have 3 replicate the portion of 1 that it covers, resulting in painting over the top of 2.

              Rectangle {
                id: bottom
                color: "red"
                Rectangle {
                  width: bottom.width / 2
                  height: bottom.height
                  color: "green"
                  Rectangle {
                    width: parent.width / 2
                    height: parent.height / 2
                    color: bottom.color
                  }
                }
              }
              

              Depending on the source of the bottom layer, the top layer might use an Image, ShaderEffect, or something else entirely. A downside to this strategy is that everything that might be impacted must redraw its visible area, as opposed to calculating the impacted area and only redrawing there. This strategy also becomes more complicated if graphics from multiple layers need to be repeated.

              R Offline
              R Offline
              Redman
              wrote on 17 Feb 2025, 06:41 last edited by
              #6

              @jeremy_k Thank you for your input. It seems I have to rethink the concept.

              1 Reply Last reply
              0

              1/6

              13 Feb 2025, 14:28

              • Login

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