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. Painting inside a transformed Canvas
QtWS25 Last Chance

Painting inside a transformed Canvas

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 929 Views
  • 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.
  • T Offline
    T Offline
    tptb
    wrote on last edited by
    #1

    Hi,

    I have trouble drawing inside a Canvas if the renderStrategy is not Canvas.Immediate after/during a fast resize of the window.

    In the image https://www.dropbox.com/s/tmbht4g19sqa9kl/QtPieSlice.png only pieslice1(blue) is correctly rendered,
    pieslice2(yellow) is not centred and sometime parts of the rendering are missing.

    Am I missing something using the Canvas?

    Regards,
    Bernd

    PieSlice.qml:
    @
    import QtQuick 2.0

    Canvas {
    antialiasing: true

    property string color: "green"
    property real angle: Math.PI/6.0

    onAngleChanged: requestPaint()
    onPaint: {
    var w = width
    var h = height
    var a = angle
    var ctx = getContext('2d');
    ctx.save();
    ctx.clearRect(0, 0, w, h);
    ctx.translate(w/2.0, h/2.0);
    ctx.fillStyle = color;
    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.arc(0, 0, Math.min(w, h)/2.0, -a/2.0, a/2.0, false);
    ctx.closePath();
    ctx.fill();
    ctx.restore();
    }
    }

    @

    main.qml:
    @
    import QtQuick 2.0

    Item {
    width:600
    height:600

    PieSlice {
    id: pieslice1
    anchors.fill: parent
    renderStrategy: Canvas.Immediate
    color: "blue"
    opacity: 0.5

    NumberAnimation on rotation {
    running: true
    loops: Animation.Infinite
    from: 0
    to: 360
    duration: 10000
    }
    }

    PieSlice {
    id: pieslice2
    anchors.fill: parent
    color: "yellow"
    opacity: 0.5

    NumberAnimation on rotation {
    running: true
    loops: Animation.Infinite
    from: 0
    to: 360
    duration: 7000
    }
    }
    }
    @

    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