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. Animating in Canvas
Forum Updated to NodeBB v4.3 + New Features

Animating in Canvas

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 918 Views 2 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.
  • imyrvoldI Offline
    imyrvoldI Offline
    imyrvold
    wrote on last edited by
    #1

    I have the following qml canvas element, that fills an arc which I want to animate. The percent property goes from 0 to 100, and I want to smooth the filling with the commented out animation. The problem is that when I uncomment the behavior, the percent property is constant 100, and I don't know why.

    Do anyone have a hint to what I could do here?

    import QtQuick 2.0

    Canvas {
    id: canvas
    width: 300
    height: 300
    antialiasing: true
    property color fillStyle: "#ffffff" // white
    property double percent: 100

    // Behavior on percent {
    // NumberAnimation {
    // id: thermobehavior
    // easing: {
    // type: Easing.OutElastic
    // amplitude: 1.0
    // period: 0.5
    // }
    // }
    // }

    onPaint: {
        var ctx = getContext("2d")
        var radius = 220
    
        ctx.clearRect(0,0,300,300)
    
        ctx.fillStyle = canvas.fillStyle
        ctx.strokeStyle = canvas.fillStyle
        ctx.lineWidth = 2
        ctx.beginPath()
        ctx.moveTo(0,280)
        ctx.lineTo(60,280)
        ctx.lineTo(60,275)
        ctx.lineTo(0,275)
        ctx.fill()
        ctx.stroke()
    
        ctx.beginPath()
        ctx.moveTo(60,280)
        ctx.arcTo(60,10,300,10,radius)
        ctx.lineTo(300,10)
    
        ctx.lineTo(300,20)
        ctx.arcTo(70,20,70,280,radius-10)
        ctx.lineTo(70,280)
        ctx.lineTo(60,280)
        ctx.stroke()
    
        ctx.clip()
        ctx.beginPath()
        ctx.arc(300,280, 280, Math.PI,Math.PI+percent/100*0.5*Math.PI)
        ctx.lineTo(300,280)
        ctx.fillStyle = "white"
        ctx.fill()
    }
    

    }

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

      It probably because the Behavior property doesn’t detect the change. Try changing the percent in Component.onCompleted instead:

      ...
      property double percent: 0
      Behavior on percent {
      ...
      }
      ...
      Component.onCompleted: percent = 100
      

      157

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hualet
        wrote on last edited by
        #3

        I think you also should repaint the canvas while the percent prop's changing..

        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