[Interest] PathView item positioning

Mitch Curtis mitch.curtis at digia.com
Thu Jul 3 15:51:45 CEST 2014


I have a PathView with 3 items. The view is large enough to fit all 3 
items without any spacing between them. Given the code below, why does 
the first item sit at half its height *above* the top of the view?

import QtQuick 2.2

Rectangle {
     width: 220
     height: 220
     color: "#494d53"

     PathView {
         id: view
         width: 100
         height: delegateHeight * pathItemCount
         model: ["A", "B", "C"]
         pathItemCount: 3
         anchors.centerIn: parent

         Rectangle {
             anchors.fill: parent
             color: "transparent"
             border.color: "darkorange"
         }

         property int delegateHeight: 0

         activeFocusOnTab: true
         Keys.onDownPressed: view.incrementCurrentIndex()
         Keys.onUpPressed: view.decrementCurrentIndex()

         delegate: Rectangle {
             width: view.width
             height: textItem.height
             border.color: "red"

             onYChanged: if (index == 0) print(y, height)
             onHeightChanged: if (index == 0) view.delegateHeight = 
textItem.height

             Text {
                 id: textItem
                 text: modelData
             }
         }

         path: Path {
             startX: view.width / 2
             startY: 0
             // Works
//            startY: view.delegateHeight / 2
             PathLine {
                 x: view.width / 2
                 y: view.pathItemCount * view.delegateHeight
                 // Works
//                y: view.pathItemCount * view.delegateHeight + 
view.delegateHeight / 2
             }
         }

         highlight: Rectangle {
             width: view.width
             height: view.delegateHeight
             visible: PathView.onPath
             color: "blue"
             opacity: 0.5
             z: 200
         }
     }
}

Cheers.



More information about the Interest mailing list