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

QPainter rotation angle draw lines,has some problem

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.2, 6.5.1
    • GUI: Painting
    • None
    • Windows

    Description

      The rotation angle draw lines. The lines drawn by qpainter default setting are uneven, but the lines drawn by qml canvas default setting are uniform.
      Because qml canvas default capStyle is flat. Why does capStyle affect uniformity?

      import QtQuick 2.15
      
      Canvas {
          id: control
      
          property real mLineCount: 360 * 2
          property real mRotation: 0
      
          onPaint: {
              var r = Math.min(width, height) / 2 - 2
              var ctx = getContext("2d")
              ctx.clearRect(0, 0, width, height)
      
              ctx.save()
              ctx.translate(width / 2, height / 2)
              ctx.strokeStyle = Qt.rgba(0.5, 0, 0, 1)
              ctx.lineWidth = 0.5 // + 1E-7
              // Qml default flat, qpainter default square
              // If not flat, multiple rotate will be uneven
              ctx.lineCap = "square"
              for (var i = 0; i < mLineCount; i++)
              {
                  // If not save/restore, multiple rotate will be uneven
                  ctx.save()
                  ctx.rotate((mRotation + 360.0 / mLineCount * i) * Math.PI / 180.0)
                  ctx.beginPath()
                  ctx.moveTo(0, 0)
                  ctx.lineTo(r, 0)
                  ctx.stroke()
                  ctx.restore()
              }
              ctx.restore()
          }
      }
      
      

      Attachments

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

        Activity

          People

            vgt Eirik Aavitsland
            gongjianbo1992 建波 龚
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes