1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtCore import QObject, pyqtSlot, QVariant,QUrl
class App(QObject):
def __init__(self, context, parent=None):
super(App, self).__init__()
self.win = parent
self.win.findChild(QObject, "ok").clicked.connect(self.test)
self.ctx = context
def test(self):
self.win.findChild(QObject, "labelCo").setProperty("text", "Hello world")
if __name__ == "__main__":
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
ctx = engine.rootContext()
engine.load('Classe.qml')
win = engine.rootObjects()[0]
py_app = App(ctx,win)
ctx.setContextProperty("py_App", py_app)
win.show()
sys.exit(app.exec()) |
Partager