Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved]Highlight and PathView don't work, do not understand why !



  • Hi,

    First, I'm sorry for my english, I'm french ;)
    Then, Sorry again if the question is obvious, I began QML a few days ago ...

    So now, the problem !
    I want to make an Picture gallery, with a path view to select the picture displayed.
    I would like to center on my pathview the item which is currently displayed (the current index).
    I use the properties "preferredHighlightBegin" and "preferredHighlightEnd", with an highlight delegate, but it doesn't work, and I do not understand why ... So, here is my code :
    @
    //Delegate for displaying images in the gallery
    Component{
    id:imageDelegate
    Image {
    id:delegateContainer
    source:model.image
    height:imagesView.height
    width: imagesView.height*sourceSize.width/sourceSize.height
    smooth: true
    scale:PathView.scale;

        }
    }
    

    //Highlight delegate
    Component{
    id:highlightComponent
    Rectangle{
    id:highlightBox
    border.color: "red"
    border.width: 5
    color:"transparent"
    width: 200
    height: 200
    }
    }

    //The path view item
    PathView{
    id:imagesView;
    height: parent.height
    width: parent.width*0.80
    anchors.centerIn: parent

        model: imageModel;
        delegate:imageDelegate;
        highlight: highlightComponent
    

    //my Highlight should be in the middle of the root gallery (Rectangle which contain the pathview--)
    preferredHighlightBegin: rootGallery.width/2
    preferredHighlightEnd: rootGallery.width/2
    //I tried with PathView.StrictlyEnforceRange, the highlight was on the left, with ApplyRange it is on the Right
    highlightRangeMode: PathView.ApplyRange
    focus:true;
    currentIndex: Math.floor(imagesView.count/2);
    path: Path{
    startX: rootGallery.x; startY:rootGallery.y;
    PathAttribute{name: "scale";value: 0.25}
    PathLine{ x:imagesView.width/2; y:imagesView.height*0.80;}
    PathAttribute{name: "scale";value: 1}
    PathLine{ x:imagesView.width; y:0;}
    PathAttribute{name: "scale";value:0.25}
    }
    }
    @

    Thanks by advance for your answers !



  • The preferred values must be in the range 0.0-1.0 for preferredHighlightBegin/End. So, set it to 0.5 is ok :D



  • Ok, I am stupid. I will wrote RTFM on a post-it and stick it on my screen ...
    Thanks a lot !


Log in to reply