Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QTableWidget Custom Widget High Memory usage Optimization

    General and Desktop
    2
    3
    215
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Emrecp
      Emrecp last edited by Emrecp

      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
      

      widget.png
      without widget.png

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Emrecp 1 Reply Last reply Reply Quote 3
        • Emrecp
          Emrecp @SGaist last edited by

          @SGaist Thanks for quick answer :)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post