是否可以动态地(在实例化期间)选择不同类型的子组件?
例如,一些伪代码(使用QT5.9):
//MyComp.qml
import QtQuick 2.9
import QtQuick.Layouts 1.3
Item {
property bool useLayout: true
//Here I want to allow the user to choose
//whether a ColumnLayout or Column is used
//(e.g., by means of the useLayout property)
我想使用Python动态地将自定义组件添加到我的view.qml上,但是我不确定我的方法,因为我在结果窗口中看不到Button.qml组件。理想情况下,我希望能够将几行按钮实例化到ColumnLayout中。顺便说一下,Button.qml自定义快速示例/演示按钮,其源代码我也包含在下面。它不是PySide6库中的QtQuick Button.qml 我以为我可以直接从view.qml调用函数,但显然不能?我已经看到了另一种方法,它涉及到使用单独的Javascript文件,但如果可能的话,我希望避免这样做。 Main.py import os
from pathlib import Path