首页| 论坛| 消息

标题:Qml绘图问题
作者:songhuirong1
日期:2019-05-06 11:43
内容:

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


#1 [songhuirong1 05-06 16:20]
自己解决了。
#2 [青空飞羽 05-06 17:25]
每次绘制时都需要重置context状态

回复 发表
主题 版块