gpt4 book ai didi

python - 如何在 PySide 中添加选项卡

转载 作者:行者123 更新时间:2023-11-30 23:21:26 24 4
gpt4 key购买 nike

我正在尝试为 2 个网格布局添加选项卡,但是当我运行代码时,似乎没有选项卡。

我认为

wid_inner.tab = QtGui.QTabWidget()

未将选项卡正确添加到网格

import sys
from PySide import QtGui


if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)

# setting the outter widget and layout
wid = QtGui.QWidget()
grid = QtGui.QGridLayout()
wid.setLayout(grid)

# setting the inner widget and layout
grid_inner = QtGui.QGridLayout()
wid_inner = QtGui.QWidget()
wid_inner.setLayout(grid_inner)

# add the inner widget to the outer layout
grid.addWidget(wid_inner)

# add tab frame to widget
wid_inner.tab = QtGui.QTabWidget()

# create tab
new_tab = QtGui.QWidget()
grid_tab = QtGui.QGridLayout()
grid_tab.setSpacing(10)
new_tab.setLayout(grid_tab)
new_tab.tab_name_private = "test1"
wid_inner.tab.addTab(new_tab, "test1")

# create tab 2
new_tab2 = QtGui.QWidget()
new_tab2.setLayout(grid_tab)
wid_inner.tab.addTab(new_tab2, "test2")

wid.show()
sys.exit(app.exec_())

如有任何帮助,我们将不胜感激

最佳答案

您需要为每个内部小部件提供父级,并且选项卡小部件 wid_inner.tab 未添加到任何布局中。建立布局似乎有点复杂...您考虑过使用 QtDesigner 吗?

wid = QtGui.QWidget()
grid = QtGui.QGridLayout(wid)
wid.setLayout(grid)

# setting the inner widget and layout
grid_inner = QtGui.QGridLayout(wid)
wid_inner = QtGui.QWidget(wid)
wid_inner.setLayout(grid_inner)

# add the inner widget to the outer layout
grid.addWidget(wid_inner)

# add tab frame to widget
wid_inner.tab = QtGui.QTabWidget(wid_inner)
grid_inner.addWidget(wid_inner.tab)

# create tab
new_tab = QtGui.QWidget(wid_inner.tab)
grid_tab = QtGui.QGridLayout(new_tab)
grid_tab.setSpacing(10)
new_tab.setLayout(grid_tab)
new_tab.tab_name_private = "test1"
wid_inner.tab.addTab(new_tab, "test1")

# create tab 2
new_tab2 = QtGui.QWidget(wid_inner.tab)
new_tab2.setLayout(grid_tab)
wid_inner.tab.addTab(new_tab2, "test2")

wid.show()
app.exec_()

关于python - 如何在 PySide 中添加选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24965432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com