PyQt/partner_625781186/QML_QtQuick_PY/python_QML调用基础/4-Python调用QML函数/qml-test4.py

30 lines
693 B
Python
Raw Normal View History

2018-04-16 23:17:02 +08:00
# -*- coding: utf-8 -*-
'''
4Python调用QML函数
QML中创建一个函数
Python中创建一个rootObject对象并连接这个函数
例子中每隔1s指针会旋转45 deg;
'''
from PyQt5.QtCore import QUrl, QTimer
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQuick import QQuickView
if __name__ == '__main__':
path = 'test4.qml' # 加载的QML文件
app = QGuiApplication([])
view = QQuickView()
view.engine().quit.connect(app.quit)
view.setSource(QUrl(path))
view.show()
timer = QTimer()
timer.start(2000)
root = view.rootObject()
timer.timeout.connect(root.updateRotater) # 调用QML函数
app.exec_()