Circular ListView/ PathView



  • Hi,
    I have a ListView where the current Index is increment/decrement when I press Key_Right/Key_Left.
    If the current index is the last, I would like when if press key right the new current index be 0.
    I have tried with a PathView but my problem is that spacing between each item is the same but I have item with several width.
    This is my QML :

    Window {
        visible: true
        width: 500
        height: 500
        Rectangle{
            anchors.fill: parent
            id: myView
            PathView {
                id:myList
                currentIndex: model/2
                anchors.fill: parent
                property int widthAllList: (widthItemSelect+widthItemNotSelect*(model-1))
                property int widthItemSelect: 150
                property int widthItemNotSelect: 50
                anchors.horizontalCenter: parent.horizontalCenter
                preferredHighlightBegin: 0.5
                preferredHighlightEnd: 0.5
                model: 10
                delegate: Rectangle {
                    color:"#bbbbbb"
                    border.color: "black"
                    anchors.verticalCenter: parent.verticalCenter
                    property bool isCurrentRemote: myList.currentIndex == index
                    width: isCurrentRemote? myList.widthItemSelect: myList.widthItemNotSelect;
                    height:isCurrentRemote? myList.widthItemSelect: myList.widthItemNotSelect
                    Text { text : index; anchors.centerIn: parent}
                }
                path: Path {
                    id:myPath
                    startX: (myView.width-myList.widthAllList)/2
                    startY: myView.height/2
                    PathLine { x: myPath.startX+myList.widthAllList; y:myView.height/2 }
                }
                focus: true
                Keys.onLeftPressed: decrementCurrentIndex()
                Keys.onRightPressed: incrementCurrentIndex()
            }
        }
    }
    

    The problem is the the currentIndex+1 and currentIndew-1 is too close of the current index.
    I have :

           -----
     --  -|     |-  -- 
    |  || |     | ||  |
     --  -|     |-  -- 
           -----
    

    and I would like :

             -----
     --  -- |     | --  -- 
    |  ||  ||     ||  ||  |
     --  -- |     | --  -- 
             -----
    

    If I use ListView, I have the right display but the behavior is wrong.
    How can I solve my problem ?

    Thank you for your help.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.