def paintEvent(self, *args): #TODO OPTIMISE FOR MULTIPLE REPETITIVE CALL super().paintEvent(*args) if self.current_silhouette is not None: # Génération du QPainter print("update started") painter = QPainter(self) # Effacer la pose précédente painter.eraseRect(self.rect()) # get x axis coordonate of the center of the player 1st on the left left_center = self.player_rect.left( ) + 0.5 * self.player_rect.width() - self.player_pixel_spacing * ( len(self.current_silhouette) - 1) * 0.5 n = len(self.current_silhouette) for k in random.sample(range(n), n): vertical_random = self.vertical_random_ratio * self.pose_hauteur * random.random( ) new_pixmap = QPixmap(self.pose_largeur, self.pose_hauteur) new_pixmap.fill(self.colors[k]) new_pixmap.setMask(self.current_silhouette[k].pixmap.scaled( self.pose_largeur, self.pose_hauteur).mask()) painter.drawPixmap( int(left_center + k * self.player_pixel_spacing - (self.pose_largeur * 0.5)), self.player_rect.top() + vertical_random, self.pose_largeur, self.pose_hauteur, new_pixmap)
def updatePixmap(self, alpha): """ Update the pixmap for the current transition. This method first clears the output pixmap. It then draws the starting pixmap followed by the ending pixmap. Each pixmap is drawn with complementary alpha values. """ out = self.outPixmap() painter = QPainter(out) painter.eraseRect(0, 0, out.width(), out.height()) painter.setOpacity(1.0 - alpha) painter.drawPixmap(QPoint(0, 0), self.startPixmap()) painter.setOpacity(alpha) painter.drawPixmap(QPoint(0, 0), self.endPixmap())
def updatePixmap(self, alpha): """ Update the pixmap for the current transition. This method first clears the output pixmap. It then draws a pixmap using the given alpha value. An alpha value less than zero indicates that the starting pixmap should be drawn. A value greater than or equal to zero indicates the ending pixmap should be drawn. """ out = self.outPixmap() painter = QPainter(out) painter.eraseRect(0, 0, out.width(), out.height()) if alpha < 0.0: alpha = -1.0 * alpha source = self.startPixmap() else: source = self.endPixmap() painter.setOpacity(alpha) painter.drawPixmap(QPoint(0, 0), source)