Ich versuche, Python, PySide und eine Beispiel-QML-Datei zu verwenden, um ein einfaches ui zu machen. Wie kann ich die Eigenschaft "value", die im QML-Steuerelement verfügbar ist, über meine Python-App festlegen? Ab sofort erscheint das "SpeedDial", kann aber nicht herausfinden, wie es seinen Wert ändert.Einstellung qml-Eigenschaft von Python?
Python-Datei:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtDeclarative import QDeclarativeView
# Create Qt application and the QDeclarative view
app = QApplication(sys.argv)
view = QDeclarativeView()
# Create an URL to the QML file
url = QUrl('SpeedDial.qml')
# Set the QML file and show
view.setSource(url)
view.show()
# Enter Qt main loop
sys.exit(app.exec_())
Die qml Datei:
import QtQuick 1.0
Item {
id: root1
property real value : 0
width: 300; height: 300
Image { id: speed_inactive; x: -9; y: 8; opacity: 0.8; z: 3; source: "pics/speed_inactive.png"
}
Image {
id: needle
x: 136; y: 86
clip: true
opacity: root1.opacity
z: 3
smooth: true
source: "pics/needle.png"
transform: Rotation {
id: needleRotation
origin.x: 5; origin.y: 65
angle: Math.min(Math.max(-130, root1.value*2.6 - 130), 133)
Behavior on angle {
SpringAnimation {
spring: 1.4
damping: .15
}
}
}
}
}
Warum nicht? Außerdem erklärt die offizielle Dokumentation [wie man das macht] (http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlromcpp.html) – Willy
@Willy, Daten können unterschiedlich angezeigt werden, aber durch Aufruf von QML von C++ wird es zu einer bestimmten Darstellung gekuppelt. Es gab ein Video von der Qt-Konferenz über die besten QML-Praktiken. – Velkan