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. z index not working for dynamic elements

z index not working for dynamic elements

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 786 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.
  • E Offline
    E Offline
    exru
    wrote on last edited by exru
    #1

    This is example with dynamic elements is working correctly. But i need what red circile be always on top for each squares on dragging, but even explicit z index not helps. How to do that?

    Rectangle{
    
                anchors.top: parent.top
                anchors.left: schemesList.right
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                color: "transparent"
    
                Component{
    
                    id: item
    
                    Rectangle{
                        x: 200
                        y: 100
                        z: 0 
                        height: 40
                        width: 180
                        color: dragTarget.containsDrag ?  "blue" :  "red"
    
                        MouseArea{
                            anchors.fill: parent
                            drag.target: parent
                        }
    
                        DropArea{
                            id: dragTarget
                            anchors.fill: parent
                        }
    
                        Rectangle{
                            id: tg
                            x: -width
                            y: height / 2
                            z: 1
                            width: 20
                            height: 20
                            radius: 100
    
                            color: mouseArea.drag.active ? "green" : "red"
                            Drag.active: mouseArea.drag.active
    
                            MouseArea{
                                id: mouseArea
                                anchors.fill: parent
                                drag.target: parent
                            }
    
                        }
    
                    }
    
                }
    
                Component.onCompleted: {
                    item.createObject(parent, {z: 0});
                    item.createObject(parent, {y:200, z: 0});
                     item.createObject(parent, {y:300, z: 0});
                }
            }
    
    J.HilkJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @exru
      this should work:

      Rectangle{
                              id: tg
                              x: -width
                              y: height / 2
                              z: mouseArea.drag.active ? 1 : 0
                              width: 20
                              height: 20
                              radius: 100
      
                              color: mouseArea.drag.active ? "green" : "red"
                              Drag.active: mouseArea.drag.active
      
                              MouseArea{
                                  id: mouseArea
                                  anchors.fill: parent
                                  drag.target: parent
                              }
      
                          }
      

      make sure to remove the explicit z value during createObject, I'm pretty sure, that breaks the binding of z: mouseArea.drag.active ? 1 : 0

      E Offline
      E Offline
      exru
      wrote on last edited by
      #5

      @J-Hilk said in z index not working for dynamic elements:

      z: mouseArea.drag.active ? 1 : 0

      I found solution. Change z-index for parent element similar as recommend you "z: mouseArea.drag.active ? 1 : 0"

      1 Reply Last reply
      0
      • E exru

        This is example with dynamic elements is working correctly. But i need what red circile be always on top for each squares on dragging, but even explicit z index not helps. How to do that?

        Rectangle{
        
                    anchors.top: parent.top
                    anchors.left: schemesList.right
                    anchors.bottom: parent.bottom
                    anchors.right: parent.right
                    color: "transparent"
        
                    Component{
        
                        id: item
        
                        Rectangle{
                            x: 200
                            y: 100
                            z: 0 
                            height: 40
                            width: 180
                            color: dragTarget.containsDrag ?  "blue" :  "red"
        
                            MouseArea{
                                anchors.fill: parent
                                drag.target: parent
                            }
        
                            DropArea{
                                id: dragTarget
                                anchors.fill: parent
                            }
        
                            Rectangle{
                                id: tg
                                x: -width
                                y: height / 2
                                z: 1
                                width: 20
                                height: 20
                                radius: 100
        
                                color: mouseArea.drag.active ? "green" : "red"
                                Drag.active: mouseArea.drag.active
        
                                MouseArea{
                                    id: mouseArea
                                    anchors.fill: parent
                                    drag.target: parent
                                }
        
                            }
        
                        }
        
                    }
        
                    Component.onCompleted: {
                        item.createObject(parent, {z: 0});
                        item.createObject(parent, {y:200, z: 0});
                         item.createObject(parent, {y:300, z: 0});
                    }
                }
        
        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @exru
        this should work:

        Rectangle{
                                id: tg
                                x: -width
                                y: height / 2
                                z: mouseArea.drag.active ? 1 : 0
                                width: 20
                                height: 20
                                radius: 100
        
                                color: mouseArea.drag.active ? "green" : "red"
                                Drag.active: mouseArea.drag.active
        
                                MouseArea{
                                    id: mouseArea
                                    anchors.fill: parent
                                    drag.target: parent
                                }
        
                            }
        

        make sure to remove the explicit z value during createObject, I'm pretty sure, that breaks the binding of z: mouseArea.drag.active ? 1 : 0


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        E 2 Replies Last reply
        0
        • J.HilkJ J.Hilk

          @exru
          this should work:

          Rectangle{
                                  id: tg
                                  x: -width
                                  y: height / 2
                                  z: mouseArea.drag.active ? 1 : 0
                                  width: 20
                                  height: 20
                                  radius: 100
          
                                  color: mouseArea.drag.active ? "green" : "red"
                                  Drag.active: mouseArea.drag.active
          
                                  MouseArea{
                                      id: mouseArea
                                      anchors.fill: parent
                                      drag.target: parent
                                  }
          
                              }
          

          make sure to remove the explicit z value during createObject, I'm pretty sure, that breaks the binding of z: mouseArea.drag.active ? 1 : 0

          E Offline
          E Offline
          exru
          wrote on last edited by
          #3

          @J-Hilk said in z index not working for dynamic elements:

          z: mouseArea.drag.active ? 1 : 0

          Not working.

          J.HilkJ 1 Reply Last reply
          0
          • E exru

            @J-Hilk said in z index not working for dynamic elements:

            z: mouseArea.drag.active ? 1 : 0

            Not working.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #4

            @exru Not enough information.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @exru
              this should work:

              Rectangle{
                                      id: tg
                                      x: -width
                                      y: height / 2
                                      z: mouseArea.drag.active ? 1 : 0
                                      width: 20
                                      height: 20
                                      radius: 100
              
                                      color: mouseArea.drag.active ? "green" : "red"
                                      Drag.active: mouseArea.drag.active
              
                                      MouseArea{
                                          id: mouseArea
                                          anchors.fill: parent
                                          drag.target: parent
                                      }
              
                                  }
              

              make sure to remove the explicit z value during createObject, I'm pretty sure, that breaks the binding of z: mouseArea.drag.active ? 1 : 0

              E Offline
              E Offline
              exru
              wrote on last edited by
              #5

              @J-Hilk said in z index not working for dynamic elements:

              z: mouseArea.drag.active ? 1 : 0

              I found solution. Change z-index for parent element similar as recommend you "z: mouseArea.drag.active ? 1 : 0"

              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