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

QTableWidget Custom Widget High Memory usage Optimization

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 446 Views
  • 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.
  • E Offline
    E Offline
    Emrecp
    wrote on 2 Feb 2021, 15:53 last edited by Emrecp 2 Feb 2021, 15:57
    #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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Feb 2021, 15:58 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

      E 1 Reply Last reply 2 Feb 2021, 16:01
      3
      • S SGaist
        2 Feb 2021, 15:58

        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.

        E Offline
        E Offline
        Emrecp
        wrote on 2 Feb 2021, 16:01 last edited by
        #3

        @SGaist Thanks for quick answer :)

        1 Reply Last reply
        0

        1/3

        2 Feb 2021, 15:53

        • Login

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