PySide Signal argument can't be retrieved from QML

自古美人都是妖i 提交于 2019-11-29 16:09:38

As of Qt 4.8, PySide doesn't handle signal parameter names at all.

But you can create a QML signal with named parameters and connect your python signal to it using Javascript:

import QtQuick 1.0

Rectangle {
    width:300; height:100


    Text {
        id: display
        text: "No signal yet detected!"

        signal reemitted(string text)
        Component.onCompleted: signaller.emitted.connect(reemitted)

        onReemitted: {
          display.text = text;        
        }
    }
}

As of Qt for Python versions 5.12.5, 5.13.1 it is working the same as in PyQt:

from PySide2.QtCore import Signal

sumResult = Signal(int, arguments=['sum'])
sumResult.emit(42)

QML:

onSumResult: console.log(sum)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!