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

Canvas doesn't paint at the correct size under certain circumstances

    XMLWordPrintable

Details

    • fea8c9026def98748f700e33e9fb41249be2b3f2

    Description

      import QtQuick 2.1
      
      Rectangle {
          width: 200
          height: 200
      
          MouseArea {
              id: showBoundsCheckBox
              anchors.horizontalCenter: parent.horizontalCenter
              width: 100
              height: 40
              onClicked: checked = !checked
      
              property bool checked: false
      
              Rectangle {
                  anchors.fill: parent
                  color: "transparent"
                  border.color: "black"
              }
      
              Text {
                  text: (showBoundsCheckBox.checked ? "Hide" : "Show") + " bounds"
                  anchors.centerIn: parent
              }
          }
      
          Item {
              implicitWidth: 32
              implicitHeight: implicitWidth
              // This works: implicitHeight: 32
              anchors.centerIn: parent
      
              Canvas {
                  id: canvas
                  width: Math.max(1, Math.min(parent.width, parent.height))
                  height: width
                  // This never paints at all: width: parent.height
                  // This works: width: parent.width
                  // This works: height: Math.max(1, Math.min(parent.width, parent.height))
      
                  onWidthChanged: print("canvas width=", width)
                  onHeightChanged: print("canvas height=", height)
      
                  onPaint: {
                      print("painting canvas at width=", width, "height=", height)
      
                      var ctx = getContext("2d");
                      ctx.reset();
                      ctx.beginPath();
                      ctx.fillRect(0, 0, width, height);
                  }
      
                  Rectangle {
                      anchors.fill: parent
                      color: "transparent"
                      border.color: "darkorange"
                      visible: showBoundsCheckBox.checked
                  }
              }
          }
      }
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-42878
          # Subject Branch Project Status CR V

          Activity

            People

              mitch_curtis Mitch Curtis
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes