PathView + ListModel



  • Hi! A have PathView and ListModel with some elements in different files.

    File with PathView and delegate:
    @
    Component {--
    id: buttonDrawer
    Item {
    width: 100; height: 100
    scale: PathView.iconScale

            Image {
                id: myIcon
                y: 10; anchors.horizontalCenter: parent.horizontalCenter
                source: icon
                smooth: true
            }
            Text {
                anchors { top: myIcon.bottom; horizontalCenter: parent.horizontalCenter }
                text: capt
                smooth: true
                color: "#c8c8c8"
            }
        }
    }
    
    Component {
        id: appHighlight
        Rectangle {
            width: 80; height: 80; color: "silver"; opacity: 0.3
        }
    }
    
    PathView {
        id: view
    
        anchors.fill: parent
        anchors.leftMargin: 200
        anchors.rightMargin: 200
    
        highlight: appHighlight
        preferredHighlightBegin: 0.5
        preferredHighlightEnd: 0.5
        focus: true
        model: Model1 {}
        delegate: buttonDrawer
        path: Path {
            startX: 10
            startY: 0
            PathAttribute { name: "iconScale"; value: 0.5 }
            PathQuad { x: 200; y: 60; controlX: 50; controlY: 100 }
            PathAttribute { name: "iconScale"; value: 1.0 }
            PathQuad { x: 390; y: 0; controlX: 350; controlY: 100 }
            PathAttribute { name: "iconScale"; value: 0.5 }
        }
    }
    

    @

    And file Model1.qml with model:
    @
    ListModel {
    ListElement {
    name: "file1.qml"
    icon: "./icon1.png"
    }
    ListElement {
    name: "file2.qml"
    icon: "./icon2.png"
    }
    ListElement {
    name: "file3.qml"
    icon: "./icon3.png"
    }
    }
    @

    How I can get value of "name" property after select PathView element? ie. after onMovementEnded event. =)

    P.S. Sorry for my english =)



  • Where do you want to get "name" property?? Inside PathView or inside delegate??



  • Inside PathView



  • I don't see a easy way of doing it..

    One thing you can try is to raise a signal from onMovementEnded, and connect to it inside delegate using "connections" element. And if that delegate element is current element ( isCurrentIndex ), call a function of PathView with "name" property.



  • Can't you just use currentIndex and index it in to your ListModel

    I mean inside your onMovementEnded, can't we do listModelId.get(currentIndex).name...

    PS : give id property value to ListModel.



  • Oh! Many Thanks! It worked!

    @
    property alias configuration: view.model

    Connections {
        target: view
        onMovementEnded: {
            var found = -1;
            for (var i=0; i < configuration.count; i++) {
                if (configuration.get(i).name == configuration.get(view.currentIndex).name) {
                    found = i;
                    break;
                }
            }
    
            console.log(configuration.get(found).name);
        }
    }
    

    @


Log in to reply
 

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