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. Canvas/QPainter bug

Canvas/QPainter bug

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
canvasqpainterzoom
3 Posts 3 Posters 1.6k 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.
  • F Offline
    F Offline
    f.serreau
    wrote on last edited by
    #1

    Hi everyone,

    I use Qt 5.11 and QtQuick 2.11, on windows OS.
    I do have a bug on one of my application:
    "
    QPainter::begin: Paint device returned engine == 0, type: 3
    QPainter::setRenderHint: Painter must be active to set rendering hints
    QPainter::setRenderHint: Painter must be active to set rendering hints
    QPainter::setCompositionMode: Painter not active
    QPainter::scale: Painter not active
    QPainter::worldTransform: Painter not active
    QPainter::worldTransform: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::brush: Painter not active
    QPainter::setBrush: Painter not active
    QPainter::font: Painter not active
    QPainter::setFont: Painter not active
    QPainter::opacity: Painter not active
    QPainter::compositionMode: Painter not active
    QPainter::setClipping: Painter not active, state will be reset by begin
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::compositionMode: Painter not active
    QPainter::setCompositionMode: Painter not active
    QPainter::setCompositionMode: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::end: Painter not active, aborted
    "

    And the area that is supposed to be painted is filled with black instead.

    In order to isolate the problem I made a small application that can reproduce the bug:

    "
    import QtQuick 2.11
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.4 as QtQuick2
    import QtQuick.Controls 1.4 as QtQuick1

    Window {
    visible: true
    width: 1024
    height: 768
    title: qsTr("Hello World")
    id:mainWindow

    QtQuick2.ScrollView {
        id: myScrollView
        anchors.fill: parent
        property real scaleFactor: 1
        onScaleFactorChanged: myCanvas.requestPaint()
    
        contentItem: Canvas {
            id: myCanvas
            width: 200 * myScrollView.scaleFactor;
            height: 200 * myScrollView.scaleFactor
    
            onPaint: {
                var ctx = getContext("2d")
                ctx.save()
                ctx.lineWidth = 4
                ctx.strokeStyle = "blue"
                ctx.fillStyle = "steelblue"
                ctx.beginPath()
                ctx.moveTo(0,0)
                ctx.lineTo(myCanvas.width,0)
                ctx.lineTo(myCanvas.width,myCanvas.height)
                ctx.lineTo(0,myCanvas.height)
                ctx.closePath()
                ctx.fill()
                ctx.stroke()
                ctx.restore()
            }
        }
    }
    
    MouseArea {
        anchors.fill: parent
        onWheel: {
            if (true )
            {
                myScrollView.scaleFactor += 0.2 * wheel.angleDelta.y / 120;
                if (myScrollView.scaleFactor < 0)
                {
                    myScrollView.scaleFactor = 0;
                }
                console.log(myScrollView.scaleFactor)
            }
        }
    }
    

    }
    "

    In this application when you scroll (zoom in) for a while, the error occurs and the view is filled with "blue" (#0000FF).

    I am using Canvas in my application. I also tried using QQuickPaintedtem or QQuickItem.
    With QQuickPaintedtem I still have the bug.
    With QQuickItem I do not have the bug no more but the render is very slow.
    Besides, I find Canvas convenient in order to draw, I would appreciate to keep using them.

    Does the problem come from the update/requestPaint method call on a wheel event?
    Is there any other solution in order to implement my zoom function?

    Regards,

    DiracsbracketD 1 Reply Last reply
    0
    • F f.serreau

      Hi everyone,

      I use Qt 5.11 and QtQuick 2.11, on windows OS.
      I do have a bug on one of my application:
      "
      QPainter::begin: Paint device returned engine == 0, type: 3
      QPainter::setRenderHint: Painter must be active to set rendering hints
      QPainter::setRenderHint: Painter must be active to set rendering hints
      QPainter::setCompositionMode: Painter not active
      QPainter::scale: Painter not active
      QPainter::worldTransform: Painter not active
      QPainter::worldTransform: Painter not active
      QPainter::setWorldTransform: Painter not active
      QPainter::pen: Painter not active
      QPainter::setPen: Painter not active
      QPainter::brush: Painter not active
      QPainter::setBrush: Painter not active
      QPainter::font: Painter not active
      QPainter::setFont: Painter not active
      QPainter::opacity: Painter not active
      QPainter::compositionMode: Painter not active
      QPainter::setClipping: Painter not active, state will be reset by begin
      QPainter::pen: Painter not active
      QPainter::setPen: Painter not active
      QPainter::pen: Painter not active
      QPainter::setPen: Painter not active
      QPainter::pen: Painter not active
      QPainter::setPen: Painter not active
      QPainter::compositionMode: Painter not active
      QPainter::setCompositionMode: Painter not active
      QPainter::setCompositionMode: Painter not active
      QPainter::pen: Painter not active
      QPainter::setPen: Painter not active
      QPainter::pen: Painter not active
      QPainter::setPen: Painter not active
      QPainter::pen: Painter not active
      QPainter::setPen: Painter not active
      QPainter::end: Painter not active, aborted
      "

      And the area that is supposed to be painted is filled with black instead.

      In order to isolate the problem I made a small application that can reproduce the bug:

      "
      import QtQuick 2.11
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.4 as QtQuick2
      import QtQuick.Controls 1.4 as QtQuick1

      Window {
      visible: true
      width: 1024
      height: 768
      title: qsTr("Hello World")
      id:mainWindow

      QtQuick2.ScrollView {
          id: myScrollView
          anchors.fill: parent
          property real scaleFactor: 1
          onScaleFactorChanged: myCanvas.requestPaint()
      
          contentItem: Canvas {
              id: myCanvas
              width: 200 * myScrollView.scaleFactor;
              height: 200 * myScrollView.scaleFactor
      
              onPaint: {
                  var ctx = getContext("2d")
                  ctx.save()
                  ctx.lineWidth = 4
                  ctx.strokeStyle = "blue"
                  ctx.fillStyle = "steelblue"
                  ctx.beginPath()
                  ctx.moveTo(0,0)
                  ctx.lineTo(myCanvas.width,0)
                  ctx.lineTo(myCanvas.width,myCanvas.height)
                  ctx.lineTo(0,myCanvas.height)
                  ctx.closePath()
                  ctx.fill()
                  ctx.stroke()
                  ctx.restore()
              }
          }
      }
      
      MouseArea {
          anchors.fill: parent
          onWheel: {
              if (true )
              {
                  myScrollView.scaleFactor += 0.2 * wheel.angleDelta.y / 120;
                  if (myScrollView.scaleFactor < 0)
                  {
                      myScrollView.scaleFactor = 0;
                  }
                  console.log(myScrollView.scaleFactor)
              }
          }
      }
      

      }
      "

      In this application when you scroll (zoom in) for a while, the error occurs and the view is filled with "blue" (#0000FF).

      I am using Canvas in my application. I also tried using QQuickPaintedtem or QQuickItem.
      With QQuickPaintedtem I still have the bug.
      With QQuickItem I do not have the bug no more but the render is very slow.
      Besides, I find Canvas convenient in order to draw, I would appreciate to keep using them.

      Does the problem come from the update/requestPaint method call on a wheel event?
      Is there any other solution in order to implement my zoom function?

      Regards,

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      Hi @f.serreau
      I have tested your example, and it works correctly with no errors.
      I tested it on Windows 10 (Fall Update), MS VS2017 and Qt 5.11.0.

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

        Hello, I encountered the same problem as you, did you solve it, it will be black or blue screen when zoomed in

        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