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. Many QML modules - Z values issue
Forum Updated to NodeBB v4.3 + New Features

Many QML modules - Z values issue

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 3 Posters 8.6k 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.
  • L Offline
    L Offline
    lgeyer
    wrote on last edited by
    #2

    Items with a higher z value are drawn on top of siblings with a lower z value.

    In your example Rectangle1 has a z of 2, Rectangle2 has a z of 1, so Rectangle1 is drawn on top of Rectangle2. If you set the z value of Rectangle2 to a higher value than the z value of Rectangle1 it will be, as expected, drawn on top of it.

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qtd1d1
      wrote on last edited by
      #3

      Sorry, that was a mistake. I corrected it.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #4

        Does this mean that - as Rectangle2 is now shown correctly at top of Rectangle1 - your problem is solved?

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qtd1d1
          wrote on last edited by
          #5

          No, now the example is correct, but the problem remains. Sorry for the confusion.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #6

            Well, but your own example diproves your assumption that each module has its own z-ordering, as Rectangle2 actually is shown on top of Rectangle1, although its z value is specified in another module.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qtd1d1
              wrote on last edited by
              #7

              Ok. youre right. My example isn't good at all. Now I have a better one, that explains my problem.
              3 Rectangles: red, yellow are defined in one QML file and blue rectangle in other QML file
              I want to get the blue rectangle in between the red and yellow rectangle.

              RectOne.qml

              @Item{
              z: 1
              Rectangle {
              id: rect1
              x: 10
              y: 10
              width: 100
              height: 62
              color: "red"
              z:2
              }
              Rectangle {
              id: rect2
              x: 20
              y: 20
              width: 100
              height: 62
              color: "yellow"
              z: 0
              }
              @

              RectTwo.qml
              @
              Item
              {
              z:1
              Rectangle {
              id: rect3
              x: 30
              y: 30
              width: 100
              height: 62
              color: "blue"
              z:1
              }
              }
              @

              Main.qml
              @Rectangle {
              width: 100
              height: 62
              z: 0

              RectOne{ x:1; y:1 }
              RectTwo{ x:1; y:1 }
              

              }@

              Result:
              Blue Rectangle: Front
              Red Rectangle: Middle
              Yellow Rectangle: Back

              Regarding to your theory the Blue rectangle should be in between the red and yellow one, because of the z-order. But it isn't.

              The main question: How do I get the blue Rectangle between the Red and yellow one?

              1 Reply Last reply
              1
              • V Offline
                V Offline
                vulee
                wrote on last edited by
                #8

                Since the z order of the outer levels(the item level) works correctly ( blue rec on top), you could break red and yellow into two modules.

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  qtd1d1
                  wrote on last edited by
                  #9

                  Is there a solution without breaking the module into two modules?

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lgeyer
                    wrote on last edited by
                    #10

                    This has actually nothing to do with different modules, but with parent items having a different z-value, which cannot be exceeded by children. This is a rule that applies to other properties as well, like opacity.
                    @
                    Rectangle {
                    width: 100
                    height: 100
                    color: "black"
                    Rectangle {
                    anchors.fill: parent
                    color: "green"
                    z: 1
                    Rectangle {
                    anchors.fill: parent
                    color: "blue"
                    z: 2
                    }
                    }
                    Rectangle {
                    anchors.fill: parent
                    color: "red"
                    z: 0
                    Rectangle {
                    anchors.fill: parent
                    color: "yellow"
                    z: 3
                    }
                    }
                    }
                    @
                    Items in QML form a hierarchical tree, and each level of a subtree has a common z-axis, which sets the stacking order of siblings. So in this case black has a z-axis, green and red have a common z-axis, blue has a z-axis and yellow has a z-axis.

                    You cannot paint across subtrees. If you want to set the z-order of different items you will have to make sure they are siblings of the same subtree (ie. they have the same parent).

                    1 Reply Last reply
                    1
                    • Q Offline
                      Q Offline
                      qtd1d1
                      wrote on last edited by
                      #11

                      Ok, thanks. Question answered.

                      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