0
我试图创建一个系统,会根据有多少产品类型自动添加选项卡,然后自动添加按钮在相应的选项卡中的项目,但由于某种原因所有的选项卡具有相同的按钮,第一个选项卡,我敢肯定,这事做的布局,但我不知道究竟是什么形象:PyQt动态添加按钮的选项卡 - 布局问题
typetab = QtGui.QTabWidget(self)
types = producttypes() ##returns a tuple with type names e.g. [('Drinks',), ('Food',)]
for name in types:
tab = QtGui.QWidget()
typetab.addTab(tab, name[0])
products = typeitems(name[0]) ## returns items of that product type [('Coke',), ('Pepsi',)]
typetablayout = QtGui.QGridLayout()
for length in range(math.floor(len(products)/5) + 1):
for width in range(5):
try:
button = QtGui.QPushButton(products[width][0])
button.setObjectName(products[width][0])
typetablayout.addWidget(button,length, width)
except IndexError:
break
print([length,width])
typetab.setLayout(typetablayout)
由于问题解决了,错误是一个简单的错误,不太可能帮助别人,所以我建议关闭这个问题。 – Trilarion