0

Im starting to work with qtquick 1.1. And i have designed a component consisting mainly out of a pathview.

Rectangle {
    id: pathViewElement

    PathView {
        id: pathView
        pathItemCount: 4
        preferredHighlightBegin: 0.5
        preferredHighlightEnd: 0.5
        highlightRangeMode: PathView.StrictlyEnforceRange
        model: myModel
        delegate: Item {
            width: valueText.width
            height: 50
            scale: 1.0-2*Math.abs(pathViewElement.width/2-(x+width/2)) / pathViewElement.width
            opacity: scale
            smooth: true
            Text {
                id: valueText
                anchors.centerIn: parent
                text: myModel.value
                font.pointSize: 35
            }
        }
        path: Path {
            startX: 0; startY: 25
            PathLine { x: pathViewElement.width; y: 25;}
        }
    }
}

This PathView is using a model called myModel. Which might be located in any other file.

The question now is the following: I'm using the same component to be able to change different values. Each of these values is coming with another QML ListModel. So how can i dynamically change the model used in the PathView (myModel)?

Also, while creating the PathView i can statically set the model using

model: MyListModel{}

where MyListModel is a qmlFile consisting only of a ListModel {} declaration. But when i dynamically create the PathView from within a third file, say MyApplication.qml I cannot set pathViewElement.model: MyListModel{} as the compiler is expecting a ";" instead of {}. Why is this?

Amit Tomar
  • 4,800
  • 6
  • 50
  • 83
Donny
  • 549
  • 2
  • 10
  • 24
  • Does this answer your question? [Change QML GridView model by javascript](https://stackoverflow.com/questions/11501266/change-qml-gridview-model-by-javascript) – ניר May 22 '22 at 17:46

1 Answers1

0

So how can i dynamically change the model used in the PathView (myModel)?

On the occurrence of respective event, you can directly change the model assigned for your view.

eg. Assuming you want this change to be done on click of some mouse button:

onClicked:
{
   pathView.model = myNewModel
}

Here, myNewModel is the id for your new model to replace with.

But when i dynamically create the PathView from within a third file, say MyApplication.qml I cannot set pathViewElement.model: MyListModel{} as the compiler is expecting a ";" instead of {}. Why is this?

Can you state this part more clearly ?

Amit Tomar
  • 4,800
  • 6
  • 50
  • 83