- Qt designer 使用自定义控件并动态加载ui文件的方法就不说了,可以看看这位博主的文章PyQt 动态加载含有自定义控件的ui文件
- 使用时发现会报错
__init__() takes 1 positional argument but 2 were given
- 原因是我的自定义控件在qt designer中有父控件
parent
,但是初始化时没有把parent
参数传进去。 - 解决方案:定义自定义控件的初始化函数时加上
*args
参数,然后调用父类初始化时传进去
class MyLabel(QLabel):
def __init__(self, *args):
super().__init__(*args)