Rectangle{ id: root property QtObject pelData property real needleData height: pelData.needle.needleLength width: pelData.needle.needleWidth color:"blue" Component.onCompleted: console.log(pelData.valueNeedleData, pelData.needle.needleLength) Shape { height: root.size width: root.size layer.enabled: true layer.samples: 8 ShapePath { id: trackShapePath capStyle: Qt.FlatCap fillColor: "transparent" strokeColor: "red" strokeWidth: pelData.mainCircleBorderWidth PathPolyline { id: ppl path: [ Qt.point(0.0, 0.0), Qt.point(3.0, 5.0), Qt.point(5.0, 8.0), Qt.point(8.0, 0.0) ] } } }}
import QtQuick 2.15import QtQuick.Controls 2.15import QtQuick.Window 2.15import QtQuick.Layouts 1.3import QtQuick.Shapes 1.15 Window { readonly property real quarterLength: 50 readonly property real minuteLength: 20 readonly property real arrowAngle: Math.PI / 6 // 30 readonly property real arrowLength: 15 width: 640 height: 480 visible: true title: qsTr("Hello World") function polarLineX(angle, length) { return length * Math.cos(angle) } function polarLineY(angle, length) { return length * Math.sin(angle) } Rectangle { id: circle anchors.centerIn: parent width: Math.min(parent.width, parent.height) height: width radius: width / 2 border.color: "red" Repeater { id: tickmarks model: 12 Shape { id: tickmark required property int index readonly property real phi: index * 2 * Math.PI / tickmarks.count x: polarLineX(phi, circle.radius) y: polarLineY(phi, circle.radius) transform: Translate { x: circle.radius y: circle.radius } ShapePath { strokeColor: "blue" strokeWidth: 1 PathLine { readonly property real tickmarkLength: index % 3 == 0 ? quarterLength : minuteLength x: polarLineX(tickmark.phi, -tickmarkLength) y: polarLineY(tickmark.phi, -tickmarkLength) } PathMove { x: 0 y: 0 } PathLine { readonly property real angle: tickmark.phi + arrowAngle x: polarLineX(angle, -arrowLength) y: polarLineY(angle, -arrowLength) } PathMove { x: 0 y: 0 } PathLine { readonly property real angle: tickmark.phi - arrowAngle x: polarLineX(angle, -arrowLength) y: polarLineY(angle, -arrowLength) } } } } }}
PathPolyline { id: ppl path: [ Qt.point(0.0, 0.0), Qt.point(3.0, 5.0), Qt.point(5.0, 8.0), Qt.point(8.0, 0.0) ] }
Rectangle { id: smallCircle readonly property real angle: 31 anchors.centerIn: parent width: circle.radius / 3 height: width radius: width / 2 border.color: "black" rotation: angle Shape { id: arrow readonly property real arrowLength: circle.radius - smallCircle.radius readonly property real arrowWidth: 10 readonly property real arrowRelativeLength: 6 readonly property real arrowTipRelativeLength: 2 anchors.verticalCenter: parent.verticalCenter anchors.left: parent.right ShapePath { fillColor: "black" scale: Qt.size(arrow.arrowLength / arrow.arrowRelativeLength, arrow.arrowWidth) PathPolyline { readonly property point topLeft: Qt.point(0, 1) path: [ topLeft, Qt.point(arrow.arrowRelativeLength - arrow.arrowTipRelativeLength, 1), Qt.point(arrow.arrowRelativeLength, 0), Qt.point(arrow.arrowRelativeLength - arrow.arrowTipRelativeLength, -1), Qt.point(0, -1), topLeft, ] } } }}
QPointF needle::calculatePoint(const double& radius, const double& angle){ QPointF pointF; pointF.setX(m_MainCircleDiameter.value() / 2 + radius * qCos((M_PI * angle) / 180.0)); pointF.setY(m_MainCircleDiameter.value() / 2 + radius * qSin((M_PI * angle) / 180.0)); return pointF;}double needle::calculateAngle(ScaleEntry& data, ValueRange& range){ AngleValueTransformer angleValueTransformer; angleValueTransformer.setAngleRangeDegrees(ValueRange<double>(-150, 150)); angleValueTransformer.setValueRange(CTcm_ValueRange<double>(range.m_Min, range.m_Max)); angleValueTransformer.setCurrentValue(data.m_ScaleEntryValue); return angleValueTransformer.calculateCurrentAngle();}