객체 생성시 Java 스크립트를 사용하여 QML 객체의 속성을 설정하고 있습니다. 숫자가 필요한 하나의 매개 변수를 제외하고는 잘 작동합니다.
이것은 스크립트를 호출합니다.
Component.onCompleted: CreateVerticalGaugeScript.createVerticalGauge(300,10,300,300,"MAP",Dashboard,"MAP");
"MAP"앞에있는 300은 필요한 숫자입니다. 다른 모든 것이 작동합니다.
var component;
var gauge;
function createVerticalGauge(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty) {
component = Qt.createComponent("verticalbargauge.qml");
console.log(setMaxValue)
if (component.status == Component.Ready)
finishCreation(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty);
else
component.statusChanged.connect(finishCreation);
}
function finishCreation(setWidth,setX,setY,setMaxValue,setID,SetValueObject,SetValueProperty) {
console.log(setMaxValue)
if (component.status == Component.Ready) {
gauge = component.createObject(adaptronicDash, {"id": setID, "gaugemaxvalue": setMaxValue,
"gaugetext": Qt.binding(function(){return SetValueObject[SetValueProperty]}),
"x": setX, "y": setY});
gauge.width = setWidth;
if (gauge == null) {
// Error Handling
//console.log("Error creating object");
}
} else if (component.status == Component.Error) {
// Error Handling
//console.log("Error loading component:", component.errorString());
}
}
이제 객체가 생성되면 QML에 NaN 값이 있습니다. jas console.log에서 300 값이 설정되었음을 보여줍니다.
생성 된 QML은 다음과 같습니다.
import QtQuick 2.8
import QtQuick.Controls.Styles 1.4
import QtQuick.Extras 1.4
import QtQml.Models 2.2
Rectangle {
id: initalID
width: 100
height: 80
color: "transparent"
antialiasing: false
Drag.active: dragArea.drag.active
property alias gaugetext: gaugetextfield.text
property alias gaugemaxvalue: gauge.maximumValue
MouseArea {
id: dragArea
width: parent.width
height: parent.height + 10 // easier to get
anchors.centerIn: parent
drag.target: parent
drag.axis: Drag.XAndYAxis
//onClicked: pieMenu.popup(mouseX, mouseY), console.log("clicked")
}
Gauge {
id: gauge
anchors.fill: parent
anchors.margins: 10
orientation : Qt.Horizontal
minorTickmarkCount: 4
tickmarkStepSize : 5000
//labelStepSize: 50
minimumValue: 0
maximumValue: 10000
//value: Dashboard.revs
Behavior on value {
NumberAnimation {
duration: 5
}
}
Text {
id: gaugetextfield
font.pixelSize: (parent.height / 3)
anchors.top : parent.top
font.bold: true
font.family: "Eurostile"
color: "white"
anchors.horizontalCenter: parent.horizontalCenter
}
style: GaugeStyle {
valueBar: Rectangle {
implicitWidth: rev.height /3
color: Qt.rgba(gauge.value / gauge.maximumValue, 0, 1 - gauge.value / gauge.maximumValue, 1)
}
}
}
}
값에 액세스 하려면 속성 별칭 gaugemaxvalue 를 사용합니다. Javascript에서 직접 숫자를 설정하면 작동합니다.
게이지 maximumValue
를 300 으로 설정 하고 tickmarkStepSize
5000입니다.
maximumValue를 30000으로 변경하거나 tickmarkStepSize를 주석 처리하여 테스트하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다