Reputation: 18123
I'm trying to add an item in a QLayout (in PyQT5) as follows:
def add_parts_BC(self):
"""This adds a tab with part B and C"""
BCVerticalLayout = QVBoxLayout()
partB = PartB()
partC = PartC()
BCVerticalLayout.addWidget(PartB, QtCore.Qt.AlignTop)
BCVerticalLayout.addWidget(PartC)
# add the layout to the tabbed widget layout
self.tabbedWidget.addTab(BCVerticalLayout, "Part B and C")
I then get the following error message:
BCVerticalLayout.addWidget(PartB, QtCore.Qt.AlignTop)
TypeError: QBoxLayout.addWidget(QWidget, int stretch=0, Qt.Alignment alignment=0): argument 1 has unexpected type 'PyQt5.QtCore.pyqtWrapperType'
I do not know where things are done wrong. Any idea?
By the way, PartA and PartB looks like this:
class PartA(QWidget):
def __init__(self):
super().__init__()
# more code here
class PartB(QWidget):
def __init__(self):
super().__init__()
# more code here
Upvotes: 0
Views: 1540
Reputation: 10951
I believe it's a TYPO error:
partB = PartB() #name of object with lower case p
partC = PartC()
BCVerticalLayout.addWidget(PartB, QtCore.Qt.AlignTop) #name of object with upper case p
so it should be:
partB = PartB()
partC = PartC()
BCVerticalLayout.addWidget(partB, QtCore.Qt.AlignTop)
Upvotes: 1