Skip to content

Instantly share code, notes, and snippets.

@0smr
Created May 20, 2021 22:54
Show Gist options
  • Save 0smr/715def4b51cc96ef027abd184125db15 to your computer and use it in GitHub Desktop.
Save 0smr/715def4b51cc96ef027abd184125db15 to your computer and use it in GitHub Desktop.
qml circular progress bar with gradient
import QtQuick 2.15
import QtGraphicalEffects 1.0 as QGE
import QtQuick.Shapes 1.15 as QQS
Item {
id: control
implicitHeight: 150
implicitWidth: 150
anchors.centerIn: parent
property alias startAngle: path.startAngle
property alias sweepAngle: path.sweepAngle
property alias start: borderGradient.start
property alias end: borderGradient.end
property alias strokeWidth:shapePath.strokeWidth
property alias gradient: borderGradient.gradient
QGE.LinearGradient {
id: borderGradient
anchors.fill: parent
start: Qt.point(0,0)
end: Qt.point(control.width,control.height)
smooth: true
visible: false
gradient: Gradient {
GradientStop { position: 0.33; color: "#c457c4" }
GradientStop { position: 1.0; color: "#4b7ec2" }
}
}
QQS.Shape {
id: mask
anchors.fill: parent
smooth: true
layer.enabled: true
layer.samples: 4
QQS.ShapePath {
id: shapePath
fillColor: 'transparent'
strokeColor: "darkBlue"
strokeWidth: 3
capStyle: QQS.ShapePath.FlatCap
PathAngleArc {
id: path
centerX: mask.width/2 ; centerY: mask.height/2
radiusX: mask.width/2 - shapePath.strokeWidth;
radiusY: mask.height/2 - shapePath.strokeWidth
startAngle: -90
sweepAngle: slider.value
}
}
}
QGE.OpacityMask {
anchors.fill: borderGradient
source: borderGradient
maskSource: mask
}
}
@0smr
Copy link
Author

0smr commented May 20, 2021

QML circular bar with gradient

  • start: defines the start point of the gradient.
  • end: defines the endpoint of the gradient.
  • gradient: defines the gradient Item.
  • startAngle: defines the sweep angle of the arc.
  • sweepAngle: defines the start angle of the arc.
  • strokeWidth: defines the start point of the gradient.

Preview

Circular ProgressBar Preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment