Important: Please read the Qt Code of Conduct -

QtQuick 2.0 Canvas Context2D clipping region doesn't resize beyond original window size

  • I ran into a problem with the clipping region in a Canvas not resizing properly. In the included simple example, if you size the app window up beyond twice its original width and/or height, you can see that the green rectangle is no longer clipped by the blue rectangle, but by a smaller region. It's as if the clip region can't grow beyond the original app window size.
    I'm new to Qt/QML, but I don't think I'm doing anything wrong here. In fact, I tried this in an HTML doc in Chrome, and it doesn't exhibit the problem.
    This is a roadblock for my development right now...
    Thanks for looking.

    @import QtQuick 2.0

    Canvas {
    id: canvas
    width: 200; height: 200;

    onPaint: {
        var c = canvas.getContext('2d')
        c.clearRect( 0, 0, width, height )
        // save stuff (clipping path in particular)
        // draw blue rectangle
        c.fillStyle = "blue"; c.rect( 0, 0, width*.5, height*.5 ); c.fill()
        // set blue rectangle as clipping path
        // draw green rectangle
        c.fillStyle = "green"; c.fillRect( 20, 20, width*.7, height*.7 );
        // restore stuff (clipping path)


Log in to reply