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. More boxes to move in the same line.
Qt 6.11 is out! See what's new in the release blog

More boxes to move in the same line.

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

    Below is the code where i create a box moving along a line
    I need help to have more independent boxes (3 or more) to move in the same line.
    @
    import QtQuick 2.0

    Rectangle {
    id: window
    width: 320
    height: 480

    Canvas {
        id: canvas
        anchors.fill: parent
        antialiasing: true
    
        onPaint: {
            var context = canvas.getContext("2d")
            context.clearRect(0, 0, width, height)
            context.strokeStyle = "black"
            context.path = pathAnim.path
            context.stroke()
        }
    }
    
    SequentialAnimation {
        running: true
        loops: -1
    
        PauseAnimation { duration: 1000 }
        //! [0]
        PathAnimation {
            id: pathAnim
    
            duration: 2000
            easing.type: Easing.InQuad
    
            target: box
            orientation: PathAnimation.RightFirst
            anchorPoint: Qt.point(box.width/2, box.height/2)
            path: Path {
                startX: 0; startY: 100
                    PathLine{x:600 ; y:100 }
                onChanged: canvas.requestPaint()
            }
        }
        //! [0]
    }
    
    Rectangle {
        id: box
    
        x: 25; y: 25
        width: 50; height: 50
        border.width: 1
        antialiasing: true
    
        Text {
            anchors.centerIn: parent
            text: "Box"
        }
    }
    

    }@

    1 Reply Last reply
    0
    • H Offline
      H Offline
      houmingc
      wrote on last edited by
      #2

      Below is my amended code for 2 boxes
      i intend to add two PathAnimation in SequentialAnimation
      @
      import QtQuick 2.0

      Rectangle {
      id: window
      width: 320
      height: 480

      Canvas {
          id: canvas
          anchors.fill: parent
          antialiasing: true
      
          onPaint: {
              var context = canvas.getContext("2d")
              context.clearRect(0, 0, width, height)
              context.strokeStyle = "black"
              context.path = pathAnim.path
              context.stroke()
          }
      }
      
      SequentialAnimation {
          running: true
          loops: -1
      
          PauseAnimation { duration: 1000 }
          //! [0]
          PathAnimation {
              id: pathAnim
      
              duration: 2000
              easing.type: Easing.InQuad
      
              target: box
              orientation: PathAnimation.RightFirst
              anchorPoint: Qt.point(box.width/2, box.height/2)
              path: Path {
                  startX: 0; startY: 100
                      PathLine{x:600 ; y:100 }
                  onChanged: canvas.requestPaint()
              }
          }
          //! [0]
              PathAnimation {
              id: pathAnim1
      
              duration: 1000
              easing.type: Easing.InQuad
      
              target: box
              orientation: PathAnimation.RightFirst
              anchorPoint: Qt.point(box.width/2, box.height/2)
              path: Path {
                  startX: 0; startY: 100
                      PathLine{x:600 ; y:100 }
                  onChanged: canvas.requestPaint()
              }
          }
      
      }
      
      Rectangle {
          id: box
      
          x: 25; y: 25
          width: 50; height: 50
          border.width: 1
          antialiasing: true
      
          Text {
              anchors.centerIn: parent
              text: "Box"
          }
      }
      

      }@

      1 Reply Last reply
      0
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        Is this the solution or what is the exact question ?

        157

        1 Reply Last reply
        0
        • H Offline
          H Offline
          houmingc
          wrote on last edited by
          #4

          question.
          I am a newbie, is there recommended pdf or site i must read?

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            Did you try the solution that I earlier posted ? Doesn't that satisfy the need ? If not, then may be I've not understood your question properly. Can you reformat the question more clearly ?

            157

            1 Reply Last reply
            0
            • H Offline
              H Offline
              houmingc
              wrote on last edited by
              #6

              want to create mulitple boxes moving on a line at different speed using qml

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                well then if it is at the same time then I think that your earlier approach is correct. For that you can create a separate Component or a QML file which will contain the PathAnimation and the Box and then later call this Component/QML file as many times you need.

                157

                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