0

so i've been trying to render an animated icon in a QPushButton.

I tried to implement this method to pyside6 but still nothing. I only have the button and text without icon. Here is the code:


def update_ani(self):
    self.button.setIcon(QIcon(self.icon.currentPixmap()))


def display_cursor(self):
    if os.path.splitext(self.file_path)[1] == '.cur':
        icon = QPixmap(self.file_path)
        self.button = QPushButton(icon=icon, text=os.path.basename(self.file_path))

    else:
        icon = QMovie(self.file_path)
        icon.frameChanged.connect(update_ani)
        self.button = QPushButton(icon=QIcon(icon.currentPixmap()), text=os.path.basename(self.file_path))
        icon.start()

Any founds ?

1 Answers1

0
    def update_ani(self):
        try:
            self.movie_button.setIcon(QIcon(self.movie_icon.currentPixmap()))
        except:
            pass
    
    
    def display_cursor(self):
        if self.file_path.endswith(".cur"):
            icon = QPixmap(self.file_path)
            self.button = QPushButton(icon=icon,  text=os.path.basename(self.file_path))
    
        else:
            self.movie_icon = QMovie(self.file_path)
            self.movie_icon.frameChanged.connect(self.update_ani)
            self.movie_button = QPushButton(icon=QIcon(self.movie_icon.currentPixmap()), text=os.path.basename(self.file_path))
            self.movie_icon.start()

#1. Make sure that the file_path is correct or it will not display.
#FULL_PATH_TO_THIS_FILE = os.path.abspath(__file__)
#IMG_FOLDER = os.path.join(FULL_PATH_TO_THIS_FILE, "resources", "images")
#GIF_PATH = os.path.join(IMG_FOLDER, "my_gif.gif")
Tanner Martin
  • 236
  • 1
  • 5