[英]error in removing item in qlayout pyqt4 python
The self.ui.verticalLayout.addWidget(MainWindow(self)) is working, But i receive an error when trying to remove the widget. self.ui.verticalLayout.addWidget(MainWindow(self))正在工作,但是尝试删除窗口小部件时出现错误。
TypeError: QLayout.removeWidget(QWidget): argument 1 has unexpected type 'PyQt4.QtCore.pyqtWrapperType' TypeError:QLayout.removeWidget(QWidget):参数1具有意外类型'PyQt4.QtCore.pyqtWrapperType'
Here are the sample codes: 以下是示例代码:
I have this separate .py file to create widget with qtableview 我有这个单独的.py文件来使用qtableview创建小部件
class MyWindow(QWidget):
pcobject =[]
def __init__(self, *args):
QWidget.__init__(self, *args)
layout = QVBoxLayout(self)
self.tableview = QTableView()
layout.addWidget(self.tableview)
........
And separate .py with vertical layout to add MyWindow Class. 并以垂直布局分隔.py以添加MyWindow类。
-Edited -编辑
from tableview import MyWindow
class QTEST(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.table = MyWindow
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.verticalLayout.addWidget(self.table))
self.ui.gridLayout.addLayout(self.ui.verticalLayout, 1, 0, 1, 1)
self.connect(self.ui.pushButton_15, QtCore.SIGNAL("clicked()"), self.table_view )
def table_view(self):
#import sip
self.ui.verticalLayout.removeItem(self.table)
#self.table.setParent(None)
#sip.delete(self.table)
#self.table = None
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = QTEST()
myapp.show()
sys.exit(app.exec_())
QTEST.table
is set to MyWindow
class, not instance. QTEST.table
设置为MyWindow
类,而不是实例。 You need to add parenthesis: self.table = MyWindow()
您需要添加括号:
self.table = MyWindow()
For reference, PyQt4.QtCore.pyqtWrapperType
is the base type of all PyQt4 classes, so if you see this error it usually means you're doing something with a class instead of an instance. 作为参考,
PyQt4.QtCore.pyqtWrapperType
是所有PyQt4类的基本类型,因此,如果看到此错误,通常意味着您正在使用类而不是实例进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.