Simple button click connection to python function

前端 未结 1 1192
一个人的身影
一个人的身影 2021-01-24 02:47

I have a very simple Qml/Python application with some content in a StackView(), with the first page containing a simple button. My question is, does EVERYTHING between Qml and P

相关标签:
1条回答
  • 2021-01-24 03:47

    Explanation:

    QML uses the MetaObject (MOC) of the QObjects to access the properties, signals and slots, in your case changePage is not a slot but a function that is not accessible from QML.

    Solution:

    The solution is to make the changePage function accessible in QML using the @pyqtSlot decorator:

    homeFunctions.py

    from PyQt5.QtCore import pyqtSlot, QObject
    
    
    class HomeFunctions(QObject):
        @pyqtSlot()
        def changePage(self):
            print("Button was pressed")
    
    0 讨论(0)
提交回复
热议问题