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. PathView skipping index 0 when producing new delegate
Forum Updated to NodeBB v4.3 + New Features

PathView skipping index 0 when producing new delegate

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 343 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.
  • T Offline
    T Offline
    ThomasKK
    wrote on last edited by
    #1

    I'm building a calendar control where the user can swipe up and down using a pathway. Starting form an index say (I'm using 2020) swiping up will decrease the current year and swiping down will increase the current year. In theory the user can swipe in either direction for eternity with no boundary because I'm calculation the current year from a function. Everything works but for some reason PathView skips the index zero for each rotation. Index zero is initially produced but it seems it is never revisited.

    The error only occurs for index 0 as far as I can see. Below is my code:
    Any help is appreciated :)

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    
    PathView {
        id: view
        anchors.fill: parent
        model: 10
        property int dHeight: 350
        property int lastIndex: 0
        property int rotation: 0
        property int startyear: 2020
    
        delegate: yearDelegate
    
        path: Path {
            startX: parent.width/2
            startY: -dHeight/2
            PathLine {
                x: parent.width/2
                y: pathItemCount *dHeight-dHeight/2
            }
        }
    
        focus: true
        pathItemCount: 3
    
        highlightRangeMode: PathView.NoHighlightRange
    
        Component {
            id: yearDelegate
            Rectangle {
                id: delegateItem
                width: parent.width
                height: dHeight
                color: "yellow"
                border.color: "black"
                visible: PathView.onPath
                opacity: 0.5
                Text {
                    id: textName
                    anchors.fill: parent
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    Component.onCompleted: {
                         text = index + ": " + setDelegateIndex(index)
                    }
                }
            }
        }
    
        function setDelegateIndex(index){
            if( (index - lastIndex) > 3 && lastIndex < 5 ){
                rotation = rotation-1;
            }
            if( (lastIndex-index) > 3 && lastIndex > 5 ){
                    rotation = rotation+1;
            }
            var offset = (rotation*10)+index;
            console.log("index: " + index + ", lastIndex: " + lastIndex + ", rotation: " + rotation + ", offset: " + offset)
            lastIndex = index;
            return startyear+offset;
        }
    }
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      ThomasKK
      wrote on last edited by
      #2

      Commenting out highlightRangeMode seem to have helped. Could this be a bug?

      //        highlightRangeMode: PathView.NoHighlightRange
      
      1 Reply Last reply
      0
      • M Offline
        M Offline
        mks__
        wrote on last edited by
        #3

        Note that the default value for PathView is PathView.StrictlyEnforceRange. If it works ok with strictly enforced range and doesn't without it means that the view does something counterintuitive here. I don't have experience with PathView, but I have had a few struggles with ListView's highlightRangeMode setting. I don't think it's a bug, once I understood what it does I simply updated my mental model of it and were able to get it to work the way I wanted. That's the 'fun' part of QML - there's more to learn than meets the eye.

        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