我有以下自动生成的列表,我想使用 PyQt5 创建分组框:
Country = ['France', 'France', 'Germany', 'Austria', 'Austria','Spain', 'Portugal','Portugal','Portugal','Spain']
Date = ['26.04', '14.05', '25.02', '18.04','15.06','18.09', '15.05', '28.03', '09.09', '10.10']
Lines = ['Line1', 'Line2', 'Line3', 'Line4', 'Line5', 'Line6', 'Line7', 'Line8', 'Line9', 'Line10']
我知道我可以得到这种类型的 Groupbox,它看起来像一个带有以下代码的表格:
import sys
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
Country = ['France', 'France', 'Germany', 'Austria', 'Austria','Spain', 'Portugal','Portugal','Portugal','Spain']
Date = ['26.04', '14.05', '25.02', '18.04','15.06','18.09', '15.05', '28.03', '09.09', '10.10']
Lines = ['Line1', 'Line2', 'Line3', 'Line4', 'Line5', 'Line6', 'Line7', 'Line8', 'Line9', 'Line10']
self.setGeometry(100, 100, 800, 600)
self.setWindowTitle('Window')
self.centralWidget = QWidget()
self.setCentralWidget(self.centralWidget)
self.mainB = QHBoxLayout()
self.GB1 = QGroupBox("")
self.GB1.setStyleSheet('QGroupBox {'
'border: 0px solid gray; }')
self.GB1.setFixedHeight(250)
self.GB1.setFixedWidth(250)
self.mainB.addWidget(self.GB1)
grid1 = QGridLayout()
for i in range(0,len(Country)):
grid1.addWidget(QLabel(Country[i]), i, 0)
grid1.addWidget(QLabel(Date[i]), i, 1)
grid1.addWidget(QLabel(Lines[i]), i, 2)
self.GB1.setLayout(grid1)
self.centralWidget.setLayout(self.mainB)
def main():
app = QApplication([])
mainWin = MainWindow()
mainWin.show()
app.exec_()
if __name__ == '__main__':
main()
但是,我想创建组框,当该国家连续出现时,它将组合与第一个列表中的相同“国家”相对应的元素。
通过查看我打算在下面执行的示例来将其可视化可能会更好:
有没有办法自动生成这些组框以达到预期的结果?