赞
踩
window = QWidget() window.resize(500, 500) # 直接使用下列方法创建会报错,抽象类无法直接使用 bnt = QAbstractButton(window) bnt.setText('按钮') # TypeError: PyQt5.QtWidgets.QAbstractButton represents a C++ abstract class and cannot be instantiated # 要是用抽象类,必须将抽象类子类化,下面介绍子类化的方法 class Bnt(QAbstractButton) pass bnt = QAbstractButton(window) bnt.setText('按钮') # 运行以上代码程序仍然会报错,但是报错的类型改变了 # NotImplementedError: QAbstractButton.paintEvent() is abstract and must be overridden # 错误提示,有一个方法是必须重写的“paintEvent()” # 正确的方法如下,但是并不能看到该控件 class Bnt(QAbstractButton) def paintEvent(self, evt
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。