def make_table(self):
self.Tab.clear()
for i in range(0,9):
self.tab1 = QWidget()
self.Tab.addTab(self.tab1, "tab" + str(i))
self.tab1.layout = QVBoxLayout(self.tab1)
self.table1 = QTableWidget()
self.table1.setColumnCount(2)
self.table1.setSortingEnabled(False)
self.table1.setRowCount(49990)
self.table1.verticalHeader().setDefaultSectionSize(20)
self.table1.setHorizontalHeaderLabels(["1", "2"])
self.table1.horizontalHeaderItem(0).setTextAlignment(Qt.AlignCenter)
self.table1.horizontalHeaderItem(1).setTextAlignment(Qt.AlignCenter)
for i in range(0, 49990):
itemtime = QTableWidgetItem(str(i))
itemvalue = QTableWidgetItem(str(i))
itemtime.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
itemvalue.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.table1.setItem(i, 0, itemtime)
self.table1.setItem(i, 1, itemvalue)
self.table1.setEditTriggers(QAbstractItemView.NoEditTriggers) #editProhibitedMode
self.tab1.layout.addWidget(self.table1)
self.tab1.setLayout(self.tab1.layout)
I want to put the data into QTabWidget whenever I press the button with the following code, but every time I press the button, the memory accumulates as shown in the picture below What's the problem?
This is a natural result because 49990 items are dynamically generated for each function call.
© 2024 OneMinuteCode. All rights reserved.