是否可以在沒有全域參考的情況下訪問動態創建的 QQuickPaintedItem 中的引擎根背景關系?
class LiveStream(QQuickPaintedItem):
def __init__(self):
QQuickPaintedItem.__init__(self)
self.backend = root_ctx.contextProperty("backend") # <- I want to remove/change this global reference
# self.getRootContext() <- Is there such a function, I cant find such a function on documentaion
...
if __name__ == "__main__":
app = QApplication()
engine = QQmlApplicationEngine()
url = QUrl.fromLocalFile(MAIN_QML)
root_ctx = engine.rootContext()
main = MainWindow(root_ctx, engine)
root_ctx.setContextProperty("backend", main)
qmlRegisterType(LiveStream, "video", 1, 0, "LiveStream")
engine.load(url)
在 QML 方面,我這樣做
function add_stream(camera, pane, pane_id) {
Qt.createQmlObject(`
import video 1.0
LiveStream {
width: ${pane.width}
height: ${pane.height}
stream_id: '${camera.id}'
stream_name: '${camera.name}'
anchors.fill: parent
}`, pane);
}
我對 pyside 或 qt/qml 很陌生,所以任何幫助都會非常好。謝謝
uj5u.com熱心網友回復:
將 Qt 屬性添加到 Livestream 并在 qml 端參考它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409023.html
標籤:
