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. Bug? Z order in Repeater?

Bug? Z order in Repeater?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 1.4k 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.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by maxwell31
    #1

    Hi,

    I have the following problem: I draw lines using a repeater. Each line has a mouse area associated, and if the mouse enters an area, another info rectangle should pop up, which would contain some information about the line. My problem is, that following lines shine through this rectangle. Here is a code which reproduces my problem:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        ListModel {
            id: linemodel
    
            ListElement {
                x: 10
    
            }
            ListElement {
                x: 20
    
            }
            ListElement {
                x: 100
            }
            ListElement {
                x: 120
            }
    
        }
        Repeater {
            id: myRepeater
            anchors.fill: parent
            model: linemodel
            delegate: line
            //delegate: Text {text: "Mark time"+timeStart}
        }
    
        Component {
            id: line
            Rectangle {
                x: model.x
                width: 2
                height: 480
                color : "black"
                MouseArea {
                    id: lineMouseArea
                    anchors.fill: parent
                    acceptedButtons: Qt.NoButton
                    hoverEnabled: true
                    onEntered: {
                        infoRectangle.visible=true
                    }
                    onExited: {
                        infoRectangle.visible=false
                    }
                }
                Rectangle {
                    id: infoRectangle
                    width: 200
                    height: 300
                    border.color: "black"
                    color: "white"
                    visible: false
                    x: 0
                    y: lineMouseArea.mouseY
                }
            }
        }
    
    }
    
    J.HilkJ 1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      The line components are all defined in an order defined by the elements in your line model. So the line component for x: 10 is defined first, then x: 20, etc. This means that the rectangles are defined in the same order. So the order of drawing would be affected by this. The solution is to just set your z on your rectangle to be above what the lines will be.

      Rectangle {
      ...
      z: 100 
      ..
      }
      
      

      100 might be too high, I don't know. Make sure to test with lots of objects.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by maxwell31
        #3

        Did you test this? Because it is not working for me. I tested with setting z on the infoRectangle to e.g. 100, but it does not change the behaviour, the next line will still shine through, although it is at z=0 and the rectangle at z=100.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          So do you think this is a bug?

          1 Reply Last reply
          0
          • M maxwell31

            Hi,

            I have the following problem: I draw lines using a repeater. Each line has a mouse area associated, and if the mouse enters an area, another info rectangle should pop up, which would contain some information about the line. My problem is, that following lines shine through this rectangle. Here is a code which reproduces my problem:

            import QtQuick 2.12
            import QtQuick.Window 2.12
            
            Window {
                visible: true
                width: 640
                height: 480
                title: qsTr("Hello World")
            
                ListModel {
                    id: linemodel
            
                    ListElement {
                        x: 10
            
                    }
                    ListElement {
                        x: 20
            
                    }
                    ListElement {
                        x: 100
                    }
                    ListElement {
                        x: 120
                    }
            
                }
                Repeater {
                    id: myRepeater
                    anchors.fill: parent
                    model: linemodel
                    delegate: line
                    //delegate: Text {text: "Mark time"+timeStart}
                }
            
                Component {
                    id: line
                    Rectangle {
                        x: model.x
                        width: 2
                        height: 480
                        color : "black"
                        MouseArea {
                            id: lineMouseArea
                            anchors.fill: parent
                            acceptedButtons: Qt.NoButton
                            hoverEnabled: true
                            onEntered: {
                                infoRectangle.visible=true
                            }
                            onExited: {
                                infoRectangle.visible=false
                            }
                        }
                        Rectangle {
                            id: infoRectangle
                            width: 200
                            height: 300
                            border.color: "black"
                            color: "white"
                            visible: false
                            x: 0
                            y: lineMouseArea.mouseY
                        }
                    }
                }
            
            }
            
            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @maxwell31 you could try this:

            Rectangle {
                        x: model.x
                        width: 2
                        height: 480
                        color : "black"
                        z: (infoRectangle.visible ? 1 : 0)
            ....
            }
            

            If you do not assign any z values yourself, they all have z = 0 and newer (sibling zs) ones are drawn above the old ones

            assuming you remove all other z assignments this should work.


            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
            • GrecKoG Online
              GrecKoG Online
              GrecKo
              Qt Champions 2018
              wrote on last edited by GrecKo
              #6

              No, the z value is only relative to an Item's siblings and its direct parent.

              if you have this item hierarchy :

              • A (z: 0)
                • A1 (z: 1)
                • A2 (z: 0)
                • A3 (z: -1)
              • B (z: 0)

              B is above A even if they have the same z, because B is after A in the hierarchy.

              A1 and A2 are above A, because they are A's children with a z >= 0. They are below B.
              A1 is above A2.
              A3 is below A (and A1 and A2) because it has a z < 0. It is below B too.

              What you need is a Popup (or more specifically a ToolTip)

              https://doc.qt.io/qt-5/qtquick-visualcanvas-visualparent.html#stacking-order
              https://doc.qt.io/qt-5/qml-qtquick-item.html#z-prop

              1 Reply Last reply
              4
              • M Offline
                M Offline
                maxwell31
                wrote on last edited by
                #7

                Thank you! I did not know, I thought z was global.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maxwell31
                  wrote on last edited by
                  #8
                  This post is deleted!
                  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