是否可以在运行时选择导入 uic 编译文件或使用 QUiLoader() 动态加载 ui?

Is it possible to choose at runtime to import uic compiled files or dynamically load the ui with QUiLoader()?

official documentation 中所述,有两种方法可以在您的代码中导入 .ui 文件:

在我的项目中,我使用的是选项 A,但现在我想知道是否可以在项目级别选择选项 A 或选项 B在运行时,因为这样可以避免在开发过程中每次更改后都必须编译小部件

对于 Python 的 Qt,选项是使用 loadUiType:

ui_class, qt_class = loadUiType("filename.ui")

class FooWidget(QFooWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = ui_class()
        self.ui.setupUi(self)