Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget Custom Widget High Memory usage Optimization
Forum Updated to NodeBB v4.3 + New Features

QTableWidget Custom Widget High Memory usage Optimization

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 454 Views 1 Watching
  • 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.
  • EmrecpE Offline
    EmrecpE Offline
    Emrecp
    wrote on last edited by Emrecp
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      EmrecpE 1 Reply Last reply
      3
      • SGaistS SGaist

        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.

        EmrecpE Offline
        EmrecpE Offline
        Emrecp
        wrote on last edited by
        #3

        @SGaist Thanks for quick answer :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved