Michael D.
Michael D.

Reputation: 1837

How to refresh a button icon, indicating that it's working before a heavy a job starts

def generate_thumb(self):
        # -- clear preview image
        pixmap = QPixmap(self.nwidth, self.nheight)
        pixmap.fill( QColor('#C0C0C0'))
        ico = QIcon(pixmap)
        self.btn3.setIcon(ico)      
        self.btn3.show()    # still not showing 
        self.generate_thumbnail()

I want btn3 filled with a grey background visible to the user - and then to start the thumbnail generation (takes 5-10 seconds then the btn3 icon is filled again with the generated thumbnail). When I run the code I don't see the grey background at all, only the new rendered image after the generation is done.

How can I force the gui to refresh or show the grey btn3 icon and then start to generate the the new image?

Upvotes: 1

Views: 169

Answers (1)

Michael D.
Michael D.

Reputation: 1837

I just finally found the answer myself.

calling QtGui.qApp.processEvents() worked for me

def generate_thumb(self):
        # -- clear preview image
        pixmap = QPixmap(self.nwidth, self.nheight)
        pixmap.fill( QColor('#C0C0C0'))
        ico = QIcon(pixmap)
        self.btn3.setIcon(ico)      

        #  show it now!
        QtGui.qApp.processEvents()       

        self.generate_thumbnail()

Upvotes: 1

Related Questions