Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-137140

QML Canvas is not repainted if size is zero and requestPaint() called

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.8.1
    • Quick: Other
    • None
    • Tested that the behavior is the same with 6.5.3 and 6.8.1 (on macOS).
    • macOS

    Description

      If Canvas has zero size (zero width or height), and we call requestPaint(), we do not get a call to onPaint(). Due to related issue (https://bugreports.qt.io/browse/QTBUG-137119) the size change back to non-zero might also not result in onPaint().

      Example to see the effect.

      import QtQuick
      import QtQuick.Controls.Basic
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Canvas repainting")
      
          Rectangle {
              anchors.fill: mycanvas
              color: "grey"
          }
      
          Canvas {
              id: mycanvas
              anchors.centerIn: parent
              width: 100
              height: 100
              onPaint: {
                  print("onPaint", "visible:", visible, "height:", height)
                  var ctx = getContext("2d");
                  // Use random color to make it easier to see when onPaint() was called
                  ctx.fillStyle = Qt.rgba(Math.random(),Math.random(),Math.random(), 1);
                  ctx.fillRect(10, 10, width - 20, height - 20);
      
                  ctx.strokeStyle = "pink"
                  ctx.lineWidth = 4
                  ctx.beginPath()
                  ctx.moveTo(10, 10)
                  ctx.lineTo(width - 20, 50)
                  ctx.closePath()
                  ctx.stroke()
              }
          }
      
          Row {
              anchors.bottom: parent.bottom
              spacing: 10
      
              Button {
                  text: "Request paint while zero size"
                  onClicked: {
                      // This sequence does not result in mycanvas.onPaint().
                      // The explicit call to requestPaint() is ignored when size is zero.
                      mycanvas.height = 0;
                      mycanvas.requestPaint();
      
                      // No mycanvas.onPaint() from this either - see: https://bugreports.qt.io/browse/QTBUG-137119
                      mycanvas.visible = false;
                      mycanvas.height = 100;
                      mycanvas.visible = true;
                  }
              }
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            lasse.lopperi Lasse Lopperi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes