Если вы хотите манипулировать некоторой информацией QML из python, логика c должна создать объект QObject, в который посылается сигнал с параметрами, которые вы хотите отправить в QML, и устанавливать соединения в QML с помощью Connections:
import os
import random
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, QtQuick
<b>class Helper(QtCore.QObject):
customSignal = QtCore.pyqtSignal(float, float, float, arguments=['param1', 'param2', 'param3'])
def call_manipulatePieSeries(self, param1, param2, param3):
self.customSignal.emit(param1, param2, param3)</b>
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
helper = Helper()
view = QtQuick.QQuickView()
<b>view.rootContext().setContextProperty("helper", helper)</b>
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "main.qml")
view.setSource(QtCore.QUrl.fromLocalFile(filename))
view.show()
def on_timeout():
helper.call_manipulatePieSeries(
random.uniform(10, 100), random.uniform(10, 100), random.uniform(10, 100)
)
timer = QtCore.QTimer(interval=1000, timeout=on_timeout)
timer.start()
sys.exit(app.exec_())
import QtQuick 2.7
import QtQuick.Window 2.0
import QtQuick.Controls 1.4
import QtCharts 2.1
Grid {
id: grid1
width: 1024
height: 600
spacing: 10
rows: 1
columns: 2
VPieModelMapper {
id: mapper0
series: serie0
labelsColumn: 0
valuesColumn: 1
firstRow: 0
rowCount: 100
}
ChartView {
id: chart
width: 600
height: 600
antialiasing: true
animationDuration: 1000
animationOptions: ChartView.AllAnimations
title: "MyTitle"
legend.visible: false
PieSeries {
id: serie0
name: "Outer Ring"
size: 0.75
holeSize: 0.7
function manipulatePieSeries(param1, param2, param3) {
console.log("Params: ", param1, param2, param3)
}
}
}
<b>Connections{
target: helper
onCustomSignal: serie0.manipulatePieSeries(param1, param2, param3)
}</b>
}