[英]How do I apply the style to a TextField in QML? It seems "style" attribute isn't available
[英]How do I apply a RadialGradient to a Shape?
這是我到目前為止所擁有的:
RadialGradient
如下所示的藍色Shape
然而,我想要的是使用RadialGradient
作為OpacityMask
,這樣綠色Shape
的外環是 100% 不透明的,但直線應該在圖像中間逐漸變細以完全透明。 到目前為止,我的任何努力都沒有奏效。 當我將RadialGradient
和Shape
都設置為visible: false
時,除了要在其中繪制所需圖像的黑框外,我什么也得不到。
一個理想的答案還可以解釋 go 如何解決此類問題以解決問題。
import QtQuick 2.15
import QtQuick.Shapes 1.15
import QtGraphicalEffects 1.15
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.15
import QtQuick.Dialogs 1.1
Rectangle {
id: myFrame
width: 640
height: 640
Rectangle {
id: blackbox
anchors.centerIn: parent
anchors.fill: parent
color: "black"
layer.enabled: true
layer.samples: 8
RadialGradient {
id: mask
visible: true
anchors.fill: parent
gradient: Gradient {
GradientStop { position: 0.0; color: "transparent" }
GradientStop { position: 0.4; color: "blue" }
}
}
Shape {
id: myShape
x: parent.width / 2
y: parent.width / 2
visible: true
ShapePath {
fillColor: "transparent"
strokeColor: Qt.rgba(0.318, 1, 0.051, 0.9)
strokeWidth: blackbox.height * 0.02
capStyle: ShapePath.RoundCap
joinStyle: ShapePath.RoundJoin
startX: 0
startY: 0
PathAngleArc {
radiusX: 0.46 * blackbox.width
radiusY: 0.46 * blackbox.height
startAngle: 270
sweepAngle: -360 * 0.7
moveToStart: false
}
}
}
OpacityMask {
anchors.fill: parent
source: myShape
maskSource: mask
}
}
}
這就是我想出的:
import QtQuick 2.15
import QtQuick.Shapes 1.15
import QtGraphicalEffects 1.15
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.15
import QtQuick.Dialogs 1.1
Rectangle {
id: myFrame
width: 640
height: 640
Rectangle {
id: blackbox
anchors.centerIn: parent
anchors.fill: parent
color: "black"
layer.enabled: true
layer.samples: 8
RadialGradient {
id: mask
visible: false
smooth: true
anchors.fill: parent
gradient: Gradient {
GradientStop { position: 0.0; color: "transparent" }
GradientStop { position: 0.4; color: "blue" }
}
}
Shape {
id: myShape
anchors.fill: parent
visible: false
smooth: true
ShapePath {
fillColor: "transparent"
strokeColor: Qt.rgba(0.318, 1, 0.051, 0.9)
strokeWidth: blackbox.height * 0.02
capStyle: ShapePath.RoundCap
joinStyle: ShapePath.RoundJoin
startX: myShape.width / 2
startY: myShape.width / 2
PathAngleArc {
centerX: myShape.width / 2
centerY: myShape.width / 2
radiusX: 0.46 * blackbox.width
radiusY: 0.46 * blackbox.height
startAngle: 270
sweepAngle: -360 * 0.7
moveToStart: false
}
}
}
OpacityMask {
anchors.fill: parent
source: myShape
maskSource: mask
}
}
}
本質上,它設置Shape
的大小並將ShapePath
。
我認為這個問題與實際未設置的Shape
大小(大小 = 0x0)有關。 然后,其中的所有內容都寫在“視圖”之外。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.