<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Il giorno sab 11 mag 2019 alle ore 17:02 Gottfried Müller <<a href="mailto:gottfried.mueller@gmx.de">gottfried.mueller@gmx.de</a>> ha scritto:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Why appears the the QListView content in the second case so late? Does <br>
an action exist to force the display of the items before the sleep event?<br></blockquote><div><br></div><div>Laying out of elements can require some long processing, which is not done in a single event loop iteration, while the "status" update is an easier task for the application, as it only needs to repaint a very simple widget.</div><div>According to the sources, the layout process of an item view is even "delayed", through the private function doDelayedItemsLayout() of every </div><div>QAbstractItemView subclass.</div><div>To avoid this kind of issues, just call QApplication.processEvents() periodically within any time consuming process.</div><div>This obviously cannot be done for your simple sleep() case, but you can test its result with this code:</div><div><br></div><div><div><font face="courier new, monospace">    def postProcessing(self):</font></div><div><font face="courier new, monospace">        self.generateItems()</font></div><div><font face="courier new, monospace">        t = QElapsedTimer()</font></div><div><font face="courier new, monospace">        t.start()</font></div><div><font face="courier new, monospace">        while t.elapsed() < 4000:</font></div><div><font face="courier new, monospace">            while QApplication.hasPendingEvents():</font></div><div><span style="font-family:"courier new",monospace">                QApplication.processEvents()</span><br></div></div><div><br></div><div>You don't always need to check for hasPendingEvents, but in some cases it's better.</div><div><br></div><div>Also, since you're doing that amount of work within the triggered signal, it will obviously block the button down state until the method returns giving back control to the caller (the button), so it might be better to find another solution: for example, you could call the processing from an "instant" QTimer, via QTimer.singleShot(0, self.generateItems), possibly by disabling the QAction when you start to fill the model and reenabling it again as soon as the processing is completed, to avoid multiple callings.</div><div><br></div><div>As a side note (just python related), you don't need to add a return at the end of every function or method if you have nothing to return, as python implicitly returns None at the end of every function or method that does not return anything else.</div><div><br></div><div>Maurizio</div><div><br></div></div>-- <br><div dir="ltr" class="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div></div></div></div>