Python 如何为我在PyQt5中添加的每个列表创建小部件或框架?

Python 如何为我在PyQt5中添加的每个列表创建小部件或框架?,python,for-loop,pyqt,pyqt5,Python,For Loop,Pyqt,Pyqt5,事实上,我正面临一个你们中的一些人可能会觉得很简单的问题,老实说,我不知道为什么我不能解决它。。。实际上我什么都试过了 首先,这是我的代码: class UpdateFrame(QtWidgets.QFrame): def __init__(self): super().__init__() self.setStyleSheet('background-color: white;' 'border:

事实上,我正面临一个你们中的一些人可能会觉得很简单的问题,老实说,我不知道为什么我不能解决它。。。实际上我什么都试过了

首先,这是我的代码:

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))
因此,现在,这段代码创建了一个窗口,显示由
类ListFrame(qtwidts.QFrame)
创建的框架内的列表
“test1”、“test2”、“test3”、“test4”、“test5”

该列表由
update\u list
调用,该列表由
类UpdateFrame(qtwidts.QFrame):
接收,位于
for
内,它根据我之前选择的
范围内的
int
创建相同的小部件(在我的示例中,20次)

所以,我想做的是:我需要这个
for
函数接收一个列表(而不是一个数字),其中包含几个列表,GUI为每个列表创建一个新的小部件,其中包含这些列表的内容

例如:

[[“test1”、“test2”、“test3”、“test4”、“test5”]、[“test6”、“test7”、“test8”、“test9”、“test10”]]

有了这个,将会有2个小部件,每个小部件都有自己的内容

我相信我的困难在于我从来没有处理过列表中的列表,这样做会影响我的大脑

谢谢大家的帮助

那么你的循环

for conteudo in range (20):
    self.layout().addWidget(ListFrame(update_list=["test1", "test2", "test3", "test4", "test5"]))
取代

for lst in list_of_lists:
    self.layout().addWidget(ListFrame(update_list=lst))
(其中我为您的

[["test1", "test2", "test3", "test4", "test5"], ["test6", "test7", "test8", "test9", "test10"]]
所以你的循环

for conteudo in range (20):
    self.layout().addWidget(ListFrame(update_list=["test1", "test2", "test3", "test4", "test5"]))
取代

for lst in list_of_lists:
    self.layout().addWidget(ListFrame(update_list=lst))
(其中我为您的

[["test1", "test2", "test3", "test4", "test5"], ["test6", "test7", "test8", "test9", "test10"]]

好的,这正是我需要的!!非常感谢!好的,这正是我需要的!!非常感谢!