<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Repaint single item in QListView]]></title><description><![CDATA[<p dir="auto">I have subclassed QListView and QAbstractItemModel to display a list of files in IconMode. I want to use a default icon when I create and populate the view. After the view is displayed, I want to use a worker thread to create an icon from each file and then update the icon in the list view. I can not figure out how to do this. I have got everything working except that the icons in the list view do not update until I swipe the mouse across or resize the view or otherwise trigger a repaint. Instead I want them to update as they are loaded.</p>
<p dir="auto">Here's the domain class.</p>
<pre><code>class ImageFile:

    def __init__(self, path: str):
        self._path = path
        self._icon = None
        
    def getIcon(self) -&gt; QIcon:
        return self._icon if self._icon is not None else QIcon(r'resources\icons\ImageFileIcon.png')
        
    def loadIcon(self) -&gt; None:
        self._icon = QIcon(self._path)
</code></pre>
<p dir="auto">The model and view classes are boilerplate but I can post code if necessary.</p>
<p dir="auto">Here's where I update the icons.</p>
<pre><code>class MainWindow(QMainWindow):
    ...        
    def loadThumbnails(self):
        worker = Worker(self._imageFileListModel._data.loadIcons)
        worker.signals.progress.connect(self.workerProgress)
        worker.signals.finished.connect(self.workerFinished)
        self._threadpool.start(worker)
        
    def workerProgress(self, i):
        print('Loaded icon #%d' % i)
        
    def workerFinished(self):
        print('Finished loading icons')
</code></pre>
<p dir="auto">I need some way to connect the <strong>ImageFile</strong> class and the representation in the list view, then I could perform the update in <strong>MainWindow.workerProgress</strong> method or maybe by emitting a signal in the <strong>ImageFile.loadIcon</strong> method. Is this is a job that could be performed by a delegate?</p>
<p dir="auto">I'm stumped. Any suggestions gratefully received.</p>
]]></description><link>https://forum.qt.io/topic/157601/repaint-single-item-in-qlistview</link><generator>RSS for Node</generator><lastBuildDate>Sun, 25 Oct 2026 23:50:34 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/157601.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 05 Jul 2024 16:14:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Repaint single item in QListView on Wed, 10 Jul 2024 01:36:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeremy_k">@<bdi>jeremy_k</bdi></a> Thanks that worked great! I appreciate the helping hand.</p>
]]></description><link>https://forum.qt.io/post/804457</link><guid isPermaLink="true">https://forum.qt.io/post/804457</guid><dc:creator><![CDATA[nhunter]]></dc:creator><pubDate>Wed, 10 Jul 2024 01:36:40 GMT</pubDate></item><item><title><![CDATA[Reply to Repaint single item in QListView on Sat, 06 Jul 2024 02:03:36 GMT]]></title><description><![CDATA[<p dir="auto">Store the icons in the model as a <a href="https://doc.qt.io/qt-6/qt.html#ItemDataRole-enum" target="_blank" rel="noopener noreferrer nofollow ugc">DecorationRole</a>. When the custom icon is ready, call setData(), and the view will update if that index is visible.</p>
]]></description><link>https://forum.qt.io/post/804218</link><guid isPermaLink="true">https://forum.qt.io/post/804218</guid><dc:creator><![CDATA[jeremy_k]]></dc:creator><pubDate>Sat, 06 Jul 2024 02:03:36 GMT</pubDate></item></channel></rss>