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. How to manualy repaint invisible area of qml canvas?

How to manualy repaint invisible area of qml canvas?

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

    Hi! I have some code i my handler onPaint in qml Canvas. I need that this code run when app was minimized and then save canvas to the file by save() canvas method. requestPaint() don't work. this method don't emit paint for region because region is invisible, i think. have you any decision? Thank you!

    p3c0P 1 Reply Last reply
    0
    • P pnmrvvtl

      Hi! I have some code i my handler onPaint in qml Canvas. I need that this code run when app was minimized and then save canvas to the file by save() canvas method. requestPaint() don't work. this method don't emit paint for region because region is invisible, i think. have you any decision? Thank you!

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @pnmrvvtl What do you mean by invisible area ?

      157

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pnmrvvtl
        wrote on last edited by pnmrvvtl
        #3

        @p3c0 my app may be run background or minimized. and area must be repainted and then saved to external file for example "1.jpg"
        i solve problem with background painting with signal paint(rect), but on method save() app get critical error...can anybody help me?Thanks...

        p3c0P 1 Reply Last reply
        0
        • P pnmrvvtl

          @p3c0 my app may be run background or minimized. and area must be repainted and then saved to external file for example "1.jpg"
          i solve problem with background painting with signal paint(rect), but on method save() app get critical error...can anybody help me?Thanks...

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @pnmrvvtl How are you calling save ? What is the exact error ? Can you post an example ?

          157

          P 1 Reply Last reply
          0
          • p3c0P p3c0

            @pnmrvvtl How are you calling save ? What is the exact error ? Can you post an example ?

            P Offline
            P Offline
            pnmrvvtl
            wrote on last edited by pnmrvvtl
            #5

            @p3c0

            onGraphCreated: {
                        canv.isGraphCreated = 1;
                        canv.paint(0,0,canv.width,canv.height)
                        canv.save("1.jpg")
                    }
            /*     */
               
            

            canv is id of my canvas. graphcreated is my signal. this is text in qml/js console
            ASSERT: "rf.isValid()" in file items\context2d\qquickcontext2dtexture.cpp, line 660 global\qglobal.cpp: 2810

            p3c0P 1 Reply Last reply
            0
            • P pnmrvvtl

              @p3c0

              onGraphCreated: {
                          canv.isGraphCreated = 1;
                          canv.paint(0,0,canv.width,canv.height)
                          canv.save("1.jpg")
                      }
              /*     */
                 
              

              canv is id of my canvas. graphcreated is my signal. this is text in qml/js console
              ASSERT: "rf.isValid()" in file items\context2d\qquickcontext2dtexture.cpp, line 660 global\qglobal.cpp: 2810

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by p3c0
              #6

              @pnmrvvtl Looking at the source here (Line 660), the assert occurs when the rect (viz. here the canvas) is not valid. But I tested something similar on Linux and it works. Following is the code:

              import QtQuick 2.4
              
              Canvas {
                  id: root
                  width: 200
                  height: 200
              
                  property point initialpos : Qt.point(0,0)
                  property point finalpos: Qt.point(0,0)
                  property int count : 0
              
                  onPaint: {
                      var ctx = getContext("2d")
                      ctx.clearRect(0, 0, width, height);
                      ctx.lineWidth = 2
                      ctx.strokeStyle = "red"
                      ctx.beginPath()
                      ctx.moveTo(initialpos.x,initialpos.y)
                      ctx.lineTo(finalpos.x,finalpos.y)
                      ctx.stroke()
                      ctx.closePath()
                  }
              
                  Timer {
                      interval: 1000; running: true; repeat: true
                      onTriggered: {
                          initialpos = Qt.point(Math.floor(Math.random() * 200) + 1,Math.floor(Math.random() * 200) + 1)
                          finalpos = Qt.point(Math.floor(Math.random() * 200) + 1,Math.floor(Math.random() * 200) + 1)
                          root.paint(0,0,root.width,root.height)
                          root.save("/home/ashish/grab/"+count+++".jpg")
                      }
                  }
              }
              

              This code just takes snaps of Canvas and save into directory after an interval of 1 sec. This works for me and there is no assert. Also root.requestPaint() instead of root.paint(0,0,root.width,root.height) works even if the Window is minimized.
              Can you test it on your system ?

              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