其实,我面临的问题是你们中的一些人可能会觉得简单,说实话,我不知道为什么我不能解决它......我真的试过一切!如何为我在PyQt5中添加的每个列表创建一个窗口小部件或框架?
所以首先,这里是我的代码:
class UpdateFrame(QtWidgets.QFrame):
def __init__(self):
super().__init__()
self.setStyleSheet('background-color: white;'
'border: 0px solid #4f4f51;'
'border-radius: 0px;'
'margin: 0px;'
'padding: 0px;')
self.setLayout(QtWidgets.QVBoxLayout())
for conteudo in range (20):
self.layout().addWidget(ListFrame(update_list=["test1", "test2", "test3", "test4", "test5"]))
class ListFrame(QtWidgets.QFrame):
def __init__(self, update_list):
super().__init__()
self.setStyleSheet('.ListFrame{background-color: white;'
'border: 1px solid #4f4f51;'
'border-radius: 0px;'
'margin: 2px;'
'padding: 2px}')
self.setMinimumSize(500, 150)
self.setLayout(QtWidgets.QVBoxLayout())
self.layout().addWidget(_Secao(update_list, max_conteudo_exibido_int=5))
class _Secao(QtWidgets.QFrame):
def __init__ (self, conteudo_list, titulo_stylesheet = 'QLabel {color: black; font-weight: bold}', max_conteudo_exibido_int = 100):
super().__init__()
self.setLayout(QtWidgets.QGridLayout())
_content_frame = QtWidgets.QFrame()
_content_frame.setLayout(QtWidgets.QVBoxLayout())
_content_frame.setFixedWidth(380)
conteudo_a_ser_exibido = conteudo_list[:max_conteudo_exibido_int]
if len(conteudo_list) == 0:
_content_frame.layout().addWidget(QtWidgets.QLabel('--'))
self.layout().addWidget(_content_frame)
elif len(conteudo_list) > len(conteudo_a_ser_exibido):
_content_frame.layout().addWidget(QtWidgets.QLabel('...'))
self.layout().addWidget(_content_frame)
else:
conteudo_a_ser_exibido = conteudo_list[2: max_conteudo_exibido_int]
_titulo_label_01 = QtWidgets.QLabel('Versão: ')
_titulo_label_02 = QtWidgets.QLabel('Data: ')
_titulo_label_1 = QtWidgets.QLabel(conteudo_list[0])
_titulo_label_2 = QtWidgets.QLabel(conteudo_list[1])
_titulo_label_01.setStyleSheet(titulo_stylesheet)
_titulo_label_02.setStyleSheet(titulo_stylesheet)
_titulo_label_1.setStyleSheet(titulo_stylesheet)
_titulo_label_2.setStyleSheet(titulo_stylesheet)
self.layout().addWidget(_titulo_label_01, 0, 0)
self.layout().addWidget(_titulo_label_02, 0, 2)
self.layout().addWidget(_titulo_label_1, 1, 0)
self.layout().addWidget(_titulo_label_2, 1, 2)
for conteudo in conteudo_a_ser_exibido:
label_list = QtWidgets.QLabel(conteudo)
label_list.setWordWrap(True)
_content_frame.layout().addWidget(label_list)
self.layout().addWidget(_content_frame, 2, 0)
self.layout().addItem(QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding))
所以,现在,这个代码创建一个窗口,显示由class ListFrame(QtWidgets.QFrame)
创建的框架内列表"test1", "test2", "test3", "test4", "test5"
。
该列表由update_list
称为,由class UpdateFrame(QtWidgets.QFrame):
接收时,for
内部,并且它根据在所述range
int
我先前选择(在我的例子,20次)创建相同的窗口小部件;
所以,这就是我想要做的:我需要这for
函数接收一个列表(而不是一个数字),其中包含几个列表内的每个列表GUI创建一个新的小部件包含那些内容。
例如:
[[ “测试1”, “TEST2”, “TEST3”, “TEST4”, “TEST5”],[ “TEST6”, “TEST7”, “test8”,“ test9“,”test10“]]
并且随着这个,将会有2个小部件,每个小部件都有它自己的内容。
我相信我的困难在于我从来没有使用列表内部的列表,并且这样做是在与我的大脑搞砸。
谢谢大家期待任何帮助!
好吧,这正是我需要的!谢谢你很多! –
不客气。 – MarianD