Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Dynamically Construct Path and PathLines
Qt 6.12 LTS is out! See what's new in the release blog

Dynamically Construct Path and PathLines

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
path pathline
4 Posts 3 Posters 1.2k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    dmac001
    wrote on last edited by
    #1

    Hi,
    I'm trying to extend my code to refactor QtQuick 1.1 qml using a repeater or timer onTriggered JS. My ugly code (working), with 24 PathLine elements,
    Item {
    property Path myPath: Path {
    PathLine {x: 0; y: 0}
    PathLine {x: 1; y: 0}
    PathLine {x: 2; y: 0}
    ...
    PathLine {x: 23; y: 0}
    }
    }

    I've tried variations on Repeater/Model.... without success. Usually QT returns 'can't assign object to list'.

    Is there a way through code to initialize the Path with 'n' number of PathLines. Any help would be most appreciated.
    Thank you

    B fcarneyF 2 Replies Last reply
    0
    • D dmac001

      Hi,
      I'm trying to extend my code to refactor QtQuick 1.1 qml using a repeater or timer onTriggered JS. My ugly code (working), with 24 PathLine elements,
      Item {
      property Path myPath: Path {
      PathLine {x: 0; y: 0}
      PathLine {x: 1; y: 0}
      PathLine {x: 2; y: 0}
      ...
      PathLine {x: 23; y: 0}
      }
      }

      I've tried variations on Repeater/Model.... without success. Usually QT returns 'can't assign object to list'.

      Is there a way through code to initialize the Path with 'n' number of PathLines. Any help would be most appreciated.
      Thank you

      B Offline
      B Offline
      Bob64
      wrote on last edited by
      #2

      @dmac001 I haven't any experience with this, but from looking at the docs, it looks like you could programmatically assign to the pathElements property. I don't think Path supports a model-based instantiation of its children.

      1 Reply Last reply
      0
      • D dmac001

        Hi,
        I'm trying to extend my code to refactor QtQuick 1.1 qml using a repeater or timer onTriggered JS. My ugly code (working), with 24 PathLine elements,
        Item {
        property Path myPath: Path {
        PathLine {x: 0; y: 0}
        PathLine {x: 1; y: 0}
        PathLine {x: 2; y: 0}
        ...
        PathLine {x: 23; y: 0}
        }
        }

        I've tried variations on Repeater/Model.... without success. Usually QT returns 'can't assign object to list'.

        Is there a way through code to initialize the Path with 'n' number of PathLines. Any help would be most appreciated.
        Thank you

        fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        @dmac001 Use PathPolyLine and just give it a list of points.

        https://doc.qt.io/qt-6/qml-qtquick-pathpolyline.html

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dmac001
          wrote on last edited by
          #4

          I have the Path and PathLine working with the above initial declaration of Path and Pathline. What I've been trying to do is either user a timer OnTriggered to create the Path and append/push... pathElements, or, use a Repeater to create the path. Variations on things I've tried below.

          a) Timer OnTriggered,

          var pathLine = Qt.createQmlObject('import QtQuick 1.1;PathLine {x:0; y:0}',_myPath)
            if(_myPath.pathElements.length == 0) {
                  for(var j=0;j<24;j++) {
                  _myPath.pathElements.push({"x":j,"y":0})
                 }
               }
          

          b) Repeater,

          Repeater{
            	id: repeater
            	model: myModel
            		delegate: Item{
            			property ShapePath s: ShapePath{					
            			strokeWidth: 2
                PathLine{x: model.x; y: model.y}
            			}
            			Component.onCompleted: {
            				shape.data.push(s)
            			}
            		}
            	}		
            }
          

          My line chart is 48 segments and is fine for what I'm trying to do. The code is not very elegant, but works. Thanks

          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
          • Unsolved