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. [SOLVED] How use pathElement in function
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How use pathElement in function

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.7k 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.
  • C Offline
    C Offline
    CharlieDVP
    wrote on 17 Jan 2015, 22:17 last edited by
    #1

    Hello,

    I want use pathElement of a Path in a funtion, but I don't find a way to do this.
    Here is my code :

    @import QtQuick 2.4

    Canvas {
    id: canvas
    width: 500; height: 400
    contextType: "2d"
    transform: Rotation { origin.x: 0; origin.y: height/2; angle: 180; axis { x: 1; y: 0; z: 0 }}

    signal trace
    
    onTrace : {
        myCurve2.pathElements = [PathCurve { x: 75; y : 75}, PathCurve {x:200; y:150}]      
    }
    
    Path {
        id: myCurve2
        startX: 20; startY: 120
        pathElements: [
            //PathCurve { x: 75; y: 75 },
            //PathCurve { x: 200; y: 150 },
            //PathCurve { x: 325; y: 25 },
            //PathCurve { x: 400; y: 100 }
        ]
    
    }
    
    onPaint: {
        trace()
        context.strokeStyle = Qt.rgba(0,1,0);
        context.path = myCurve2;
        context.stroke();
    }
    

    }
    @

    This use of pathElements does not. Do you know how to do it right? The goal is to be able to create a curve dynamically.

    In advance thank you

    Charlie

    1 Reply Last reply
    0
    • C Offline
      C Offline
      CharlieDVP
      wrote on 19 Jan 2015, 09:19 last edited by
      #2

      To clarify, what I want is just to use PathCurve dynamically, ie by creating the curve depusi coordinates calculated in my application.

      I find it hard to believe that this is not possible.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        p3c0
        Moderators
        wrote on 20 Jan 2015, 09:42 last edited by
        #3

        Hi,

        AFAIK pathElement requires a list and list does not allow to add/remove objects, so try with var type instead since it allows to add/remove items dynamically.

        @
        import QtQuick 2.4

        Canvas {
        id: c
        width: 400; height: 200
        contextType: "2d"

        Component {
            id: comp
            PathCurve { }
        }
        
        property var paths : [
            comp.createObject(c, {"x": 75, "y": 75} )
        ]
        
        Path {
            id: myPath
            startX: 0; startY: 100
            pathElements: paths
        }
        
        onPaint: {
            context.strokeStyle = Qt.rgba(.4,.6,.8);
            context.path = myPath;
            context.stroke();
        }
        
        Component.onCompleted: {
           paths[paths.length] = comp.createObject(c, {"x": 200, "y": 150} )
           myPath.pathElements = paths
        }
        

        }
        @

        So you can play with the code in Component.onCompleted to create more objects.
        Hope this helps...

        P.S: Don't forget to "requestPaint()":http://doc.qt.io/qt-5/qml-qtquick-canvas.html#requestPaint-method to repaint the changes.

        157

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CharlieDVP
          wrote on 20 Jan 2015, 10:11 last edited by
          #4

          Hello,

          The code you propose works well.

          Small note as paths is an array JavaScript we could replace:
          @paths [paths.length] = comp.createObject (c, {"x" 200, "y": 150})@

          by
          @paths.push (comp.createObject (c, {"x" 200, "y": 150}))@

          Thank you very much.

          Charlie

          1 Reply Last reply
          0
          • P Offline
            P Offline
            p3c0
            Moderators
            wrote on 20 Jan 2015, 10:25 last edited by
            #5

            Right :) Still adhered to the old style ;)

            157

            1 Reply Last reply
            0

            1/5

            17 Jan 2015, 22:17

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved