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 + ListModel
QtWS25 Last Chance

PathView + ListModel

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 2.9k 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.
  • W Offline
    W Offline
    WeX.tmpvar
    wrote on last edited by
    #1

    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 =)

    Sorry for my english =)

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • W Offline
        W Offline
        WeX.tmpvar
        wrote on last edited by
        #3

        Inside PathView

        Sorry for my english =)

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thisisbhaskar
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thisisbhaskar
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              WeX.tmpvar
              wrote on last edited by
              #6

              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);
                  }
              }
              

              @

              Sorry for my english =)

              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