songhuirong1 |
2019-05-06 11:43 |
Qml绘图问题
初学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() } } } }
|
|