示例#1
0
class SimulatorViewer(QtGui.QFrame):
    def __init__(self, parent = None):
        super(SimulatorViewer, self).__init__(parent)
        self.__bitmap = QtGui.QPixmap()
        self.__blt_bitmap = QtGui.QImage(self.size(), QtGui.QImage.Format_ARGB32)
        self.renderer = QtRenderer(self.__blt_bitmap)
        self.__resize_on_paint = False
        # code for async calling of update
        self.update_ = self.metaObject().method(self.metaObject().indexOfMethod('update()'))

    def paintEvent(self, event):
        super(SimulatorViewer, self).paintEvent(event)
        painter = QtGui.QPainter(self)
        painter.fillRect(self.rect(),QtCore.Qt.white)
        s = self.__bitmap.rect().size()
        s.scale(self.rect().size(),QtCore.Qt.KeepAspectRatio)
        dx = (self.width() - s.width())/2
        dy = (self.height() - s.height())/2
        painter.drawPixmap(QtCore.QRect(QtCore.QPoint(dx,dy),s),self.__bitmap,self.__bitmap.rect())
        
    def update_bitmap(self):
        self.__bitmap = QtGui.QPixmap.fromImage(self.__blt_bitmap)
        # resize the canvas - at this point nothing is being drawn
        if self.__resize_on_paint:
            self.__blt_bitmap = QtGui.QImage(self.width(),
                                            self.height(),
                                            QtGui.QImage.Format_ARGB32)
            self.renderer.set_canvas(self.__blt_bitmap)          
            self.__resize_on_paint = False
        self.update()

    def resizeEvent(self,event):
        """Resize panel and canvas"""
        # use cached size and flag
        self.__resize_on_paint = True
示例#2
0
 def __init__(self, parent = None):
     super(SimulatorViewer, self).__init__(parent)
     self.__bitmap = QtGui.QPixmap()
     self.__blt_bitmap = QtGui.QImage(self.size(), QtGui.QImage.Format_ARGB32)
     self.renderer = QtRenderer(self.__blt_bitmap)
     self.__resize_on_paint = False
     # code for async calling of update
     self.update_ = self.metaObject().method(self.metaObject().indexOfMethod('update()'))