Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Controlling QML: canvas2D with 2 buttons



  • Hi Everyone,
    Am using one buttons in QML to control my canvas(circular progress ).
    On pressing button am able to create that circular progress bar perfectly.
    But once that progress bar is completed it remains there on screen and i want to use reset it and draw again one that button press again.
    Already tried reset function and clearRect but not acheive my aim.
    Anybody know how to do this stuff.



  • @aks17

    Just for testing. Instead of using clear rect try a fillRect with bright red as your clear colour. You'll soon get an idea of whether that worked or not.

    Also, if you could provide a smallish code snippet that would help.


  • Moderators

    hi @aks17

    inside your canvas, define a property bool propter, clearCanvas or something.

    Canvas{
                    id:canvas
                    anchors.fill: parent
    
                    property bool clearCanvas : false
                    onClearCanvasChanged: canvas.requestPaint()
    
                    onPaint: {
                       
                       var ctx = getContext("2d");
                       if(clearCanvas){
                            clearCanvas = false;
                            ctx.reset();
                       }
                        
    
                      //Your normal paint stuff goes hear
                    }
                }
    

    reset() removed all previous drawings.


Log in to reply