查看完整版本: [-- Qml绘图问题 --]

QTCN开发网 -> Qt QML开发 -> Qml绘图问题 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

songhuirong1 2019-05-06 11:43

Qml绘图问题

初学Qml,现在有个关于绘图的问题想请教各位。望指点。问题描述如下:
我绘制了一个矩形,里面用绿色填充,边框用红色绘制。窗体第一次运行的时候,显示正常。但是当我改变窗口大小时,显示出现了异常,红色的边框会重复绘制,导致边框叠加。请问这个问题该如何解决?代码如下:
  1. import QtQuick 2.9
    import QtQuick.Window 2.2

    Window {
        visible: true
        title: qsTr("Hello World")

        Rectangle {
            id: centerRect
            color: "#ffffff"
            anchors.fill: parent

            Canvas {
                id: mainWndCanvas
                anchors.fill: parent
                contextType: "2d"

                onPaint: {
                    context.lineWidth = 2
                    context.strokeStyle = "red"
                    context.fillStyle = "green"
                    context.rect(0, 0, width, height)
                    context.fill()
                    context.stroke()
                }
            }
        }
    }





songhuirong1 2019-05-06 16:20
自己解决了。

青空飞羽 2019-05-06 17:25
每次绘制时都需要重置context状态


查看完整版本: [-- Qml绘图问题 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled