[Qgis-developer] Refresh canvas does not work

DanielK daniel.klich at gmx.de
Wed Sep 19 09:50:18 PDT 2012


Hi,

i have my own canvas map with a layer in my plugin window. I want to
simulate a Cellular Automaton for insect dispersal, but the refreshing of
the canvas only works with a little trick. If I use refresh(), setDirty(),
update(), ... nothing happens. But if i open a MessageBox or leave the
method, the canvas will update. 

I have a button "Start" in my window and a click on it calls the following
method:

def startTest(self):
        self.width = 20
        self.height = 20
        r = QgsRubberBand(self.canvas, True)  # True = a polygon
        points = [ [ QgsPoint(0,0), QgsPoint(self.width*2,0),
QgsPoint(self.width*2,self.height*2),QgsPoint(0,self.height*2) ] ]
        r.setColor(QColor(255,255,255))
        r.setToGeometry(QgsGeometry.fromPolygon(points), None)

        # - refresh map & legend
        if hasattr(self.layer, "setCacheImage"):
           self.layer.setCacheImage( None )  
        #self.canvas.setDirty( True )
        self.layer.triggerRepaint()
        self.canvas.refresh()
        #nothing happens
        time.sleep(2)
        #only after the message box, the canvas will update
        QMessageBox.information( self.dlg ,"Info", str( self.layer.type() )
)
        time.sleep(3)
        
        self.canvas.scene().removeItem(r)


Is there any way to refresh the canvas without leaving the method
startTest() or displaying this QMessageBox ?


best regards,

DanielK




--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Refresh-canvas-does-not-work-tp5003004.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list