QTableWidget Custom Widget High Memory usage Optimization
Unsolved
General and Desktop
-
Hello,
I have QTableWidget and have ~400 rows and every rows has custom widget.
When I use Custom widget, program takes 350 MB RAM, when i disable custom widget, it takes 230 MB RAM.I am looking for any ideas to downgrade high memory usage.
CustomWidgetClass:class CustomWidgetClass(QWidget): def __init__(self, parent=None): super(CustomWidgetClass, self).__init__() self.parent = parent self.btnIptal = QLabel() self.btnDurdurDevam = QLabel() self.btnBaslat = QLabel() self.btnDurdurDevam.setPixmap(QPixmap(":/source/img/pause.png").scaled(QSize(24,24),Qt.KeepAspectRatio, Qt.SmoothTransformation)) self.btnBaslat.setPixmap(QPixmap(":/source/img/download.png").scaled(QSize(24, 24), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.btnIptal.setPixmap(QPixmap(":/source/img/Cikis2.png").scaled(QSize(24, 24), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.btnIptal.setAlignment(Qt.AlignCenter) self.btnDurdurDevam.setAlignment(Qt.AlignCenter) self.btnBaslat.setAlignment(Qt.AlignCenter) layout = QHBoxLayout() layout.addWidget(self.btnBaslat) layout.addWidget(self.btnDurdurDevam) layout.addWidget(self.btnIptal) self.chkSSDYEKUR = QCheckBox() self.yout = QLabel() self.yout.setAlignment(Qt.AlignCenter) self.yout.setPixmap(QIcon(':/source/img/YT.png').pixmap(QSize(24, 24))) layout.insertWidget(3, self.yout) layout.setContentsMargins(3, 0, 3, 0) layout.setSpacing(10) self.setLayout(layout) # when i remove this, RAM Usage drops but widgets not showing.
Here is How i set custom widget to row
buttonWid = CustomWidgetClass(self) self.liste.setCellWidget(rowPosition, 5, buttonWid) # all rows
-
Hi,
Use a custom QStyledItemDelegate. As stated in the documentation setCellWidget should only be used to show some static content.
In your case your are creating more than 2000 widgets without counting the QTableWidget.
-
Hi,
Use a custom QStyledItemDelegate. As stated in the documentation setCellWidget should only be used to show some static content.
In your case your are creating more than 2000 widgets without counting the QTableWidget.