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. Update QListWidget item
Forum Updated to NodeBB v4.3 + New Features

Update QListWidget item

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 2.2k Views 2 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 6 May 2019, 19:36 last edited by
    #2

    Hi and welcome to devnet,

    Why are you deleting your CustomItem ? If you make it properly updatable you can avoid that.

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

    1 Reply Last reply
    1
    • Z Offline
      Z Offline
      Zaher
      wrote on 6 May 2019, 20:13 last edited by
      #3

      Thanks @SGaist for the reply, but is there a documentation page of example I can read to know how to use it.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 6 May 2019, 20:20 last edited by
        #4

        On how to use what ?

        Did you already took a look at:

        • Model/View Programming
        • Item views examples
        • Model View Tutorial

        ?

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

        1 Reply Last reply
        2
        • Z Offline
          Z Offline
          Zaher
          wrote on 8 May 2019, 14:21 last edited by
          #5

          I am wonder if the model works on a diffrent thread or not?

          G 1 Reply Last reply 8 May 2019, 15:05
          0
          • Z Zaher
            8 May 2019, 14:21

            I am wonder if the model works on a diffrent thread or not?

            G Offline
            G Offline
            Gojir4
            wrote on 8 May 2019, 15:05 last edited by
            #6

            @Zaher No, models are working on the GUI main thread. See https://stackoverflow.com/questions/9485339/design-pattern-qt-model-view-and-multiple-threads.

            But this does not avoid to handle heavy process in different thread and then update the model using signal and slots.

            Z 1 Reply Last reply 8 May 2019, 15:54
            2
            • G Gojir4
              8 May 2019, 15:05

              @Zaher No, models are working on the GUI main thread. See https://stackoverflow.com/questions/9485339/design-pattern-qt-model-view-and-multiple-threads.

              But this does not avoid to handle heavy process in different thread and then update the model using signal and slots.

              Z Offline
              Z Offline
              Zaher
              wrote on 8 May 2019, 15:54 last edited by
              #7

              @Gojir4 Thanks.

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zaher
                wrote on 8 May 2019, 16:14 last edited by
                #8

                Do you have any example for edit item by code in Python using PyQt?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 8 May 2019, 21:00 last edited by
                  #9

                  What do you mean by edit ?

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

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    Zaher
                    wrote on 8 May 2019, 22:27 last edited by
                    #10

                    I issue is I want to change the icon in QListItem on condition this the code of widget of the item
                    In this code, I am reading from pass tuple "file" and depends on the condition I am choosing the icon

                    import os
                    from PyQt5 import QtGui, QtCore
                    from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QPushButton
                    
                    class CustomQWidget(QWidget):
                        def __init__(self, file, parent=None):
                            super(CustomQWidget, self).__init__(parent)
                            self.file = file
                            if self.file["l_file"]:
                                pathname = os.path.join(parent.parent.main_script_path, "icons/correct.png")
                            else:
                                pathname = os.path.join(parent.parent.main_script_path, "icons/wrong.png")
                            pixmap = QtGui.QPixmap(pathname)
                            button = QPushButton()
                            button.setStyleSheet("padding: 0px;")
                            button.setFixedSize(16, 16)
                            self.icon_size=button.size()
                    
                            # resize pixmap
                            pixmap = pixmap.scaled(button.size(), QtCore.Qt.KeepAspectRatioByExpanding, QtCore.Qt.SmoothTransformation)
                    
                            # crop pixmap - the following assumes the image aspect is always wider than the button.  if that's not the case
                            # you'll need to compare your image/button aspects and crop vertically/horizontally as necessary
                            self.cropOffsetX = (pixmap.width() - button.size().width()) / 2
                            pixmap = pixmap.copy(self.cropOffsetX, 0, button.size().width(), button.size().height())
                    
                            button.setIcon(QtGui.QIcon(pixmap))
                            button.setIconSize(button.size())
                            button.setFlat(True)
                            label = QLabel(file["n_file"])
                            layout = QHBoxLayout()
                            layout.addWidget(button, 0)
                            layout.addWidget(label, 0)
                            layout.setContentsMargins(0, 0, 0, 0)
                            self.setLayout(layout)
                    
                    

                    So, what I understand I could QStyledItemDelegate to rerender the item when I want to change the Icon I found a close question but I couldn't finger out how to connect it to the icon and how to make it render on a certain single.
                    Please, help I am desperate here, and thanks in advance.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 9 May 2019, 21:50 last edited by
                      #11

                      Something is not clear, do you want to use a delegate or have cell widgets ?

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

                      1 Reply Last reply
                      0

                      11/11

                      9 May 2019, 21:50

                      • Login

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