[英]How to use PathCubic in QML?
https://doc.qt.io/qt-5/qml-qtquick-pathcubic.html
以下代碼來自上面的鏈接,但在執行時不顯示任何行。 我看到的只是紅色矩形。 指出故障點。
import QtQuick 2.12
import QtQuick.Window 2.12
import QtGraphicalEffects 1.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle
{
height: 300; width: 300
x: 10; y: 10
color: "red"
Path
{
startX: 20; startY: 0
PathCubic {
x: 180; y: 0
control1X: -10; control1Y: 90
control2X: 210; control2Y: 90
}
}
}
}
Path 不是視覺元素,而是定義路徑的類,即處理指令(PathLine、PathPolyline、PathCubic 等)的類。
因此,如果您想使用 Shape、Canvas 等可視化 PathCubic 指令:
import QtQuick 2.0
import QtQuick.Window 2.12
import QtQuick.Shapes 1.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle{
height: 300; width: 300
x: 10; y: 10
color: "red"
Shape {
anchors.fill: parent
ShapePath {
strokeWidth: 4
strokeColor: "blue"
fillColor: "transparent"
startX: 20; startY: 0
PathCubic {
x: 180; y: 0
control1X: -10; control1Y: 90
control2X: 210; control2Y: 90
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.