def display_image(self): if not self.index == -1: self.image.clear() self.image.resize(self.image.minimumSizeHint()) file = self.images[self.index] if os.path.isfile(file): self.label_name.setText(file) self.label_numero.setText( str(self.index + 1) + ' / ' + str(len(self.images))) # image list self.image_gallery.select_row(self.index) image_reader = QImageReader(file) if image_reader.imageCount() > 1: # Animated image movie = QMovie(file) movie.setCacheMode(QMovie.CacheAll) movie.jumpToFrame(0) movie_size = movie.currentPixmap().size() self.image.setMovie(movie) self.image.resize(movie_size) movie.start() else: self.image.setPixmap(QPixmap(file)) self.image.resize(self.image.pixmap().size()) # fit image if self.action_fit_screen.isChecked(): self.fit_screen() elif self.action_fit_horizontal.isChecked(): self.fit_width() elif self.action_fit_vertical.isChecked(): self.fit_height() else: self.ratio = 1.0 self.action_zoom_in.setEnabled(True) self.action_zoom_out.setEnabled(True) # scrollbar position self.scroll_area.verticalScrollBar().setSliderPosition(0) self.scroll_area.horizontalScrollBar().setSliderPosition(0)
class MovieSplashScreen(QSplashScreen): my_size = QSize(600, 600) def __init__(self, path_to_gif: str): self.movie = QMovie(path_to_gif) self.movie.jumpToFrame(0) pixmap = QPixmap(self.my_size) QSplashScreen.__init__(self, pixmap) self.movie.frameChanged.connect(self.repaint) def showEvent(self, event: PySide6.QtGui.QShowEvent) -> None: self.movie.start() def hideEvent(self, event: PySide6.QtGui.QHideEvent) -> None: self.movie.stop() def paintEvent(self, event: PySide6.QtGui.QPaintEvent) -> None: painter = QPainter(self) pixmap = self.movie.currentPixmap() pixmap = pixmap.scaled(self.my_size) painter.drawPixmap(0, 0, pixmap)
def media_preview(self, filename): media_preview = QMovie(filename) self.preview_widget.setMovie(media_preview) self.preview_widget.movie().start() self.preview_widget.resize(media_preview.currentPixmap().width(), media_preview.currentPixmap().height())