class SplashScreen(QSplashScreen): def __init__(self): super(SplashScreen, self).__init__() self.movie = QMovie(r'20190320111722218.gif') self.movie.frameChanged.connect( lambda: self.setPixmap(self.movie.currentPixmap())) self.movie.start() def mousePressed(self, event): pass
class CustomButton(QPushButton): def __init__(self): super(CustomButton, self).__init__() self.setMinimumSize(290, 70) self.setMaximumSize(290, 70) self.setStyleSheet('QPushButton{background-color: #28a745; color: rgb(255, 255, 255); font: 24pt "IRANSans"; ' 'padding: 3px; border: none; border-radius: 6px; outline-style: none;}' 'QPushButton:pressed {background-color: #145222;border-style: inset;}') @Slot () def start(self): if hasattr(self, "gifBtn"): self.setText(None) self.gifBtn.start() @Slot () def stop(self): if hasattr(self, "gifBtn"): self.setText('ورود') self.gifBtn.stop() self.setIcon(QIcon()) def setGif(self, filename): if not hasattr(self, "gifBtn"): self.gifBtn = QMovie(self) self.gifBtn.setFileName(filename) self.gifBtn.frameChanged.connect(self.on_frameChanged) if self.gifBtn.loopCount() != -1: self.gifBtn.finished.connect(self.start) self.stop() @Slot (int) def on_frameChanged(self, frameNumber): self.setIcon(QIcon(self.gifBtn.currentPixmap())) self.setIconSize(QSize(70, 70)) #if __name__ == '__main__': # import sys # import random # app = QApplication(sys.argv) # w = QWidget() # lay = QVBoxLayout(w) # for i in range(5): # button = CustomButton() # button.setGif("animations/Rolling-white.gif") # button.clicked.connect(button.start) # #QTimer.singleShot(random.randint(3000, 6000), button.start) # #QTimer.singleShot(random.randint(8000, 12000), button.stop) # lay.addWidget(button) # w.show() # sys.exit(app.exec_())
class AnimatedSplash(QSplashScreen): def __init__(self, path): self.__movie = QMovie(path) self.__movie.jumpToFrame(0) pixmap = QPixmap(self.__movie.frameRect().size()) QSplashScreen.__init__(self, pixmap) self.__movie.frameChanged.connect(self.repaint) def showEvent(self, event): self.__movie.start() def hideEvent(self, event): self.__movie.stop() def paintEvent(self, event): painter = QPainter(self) pixmap = self.__movie.currentPixmap() self.setMask(pixmap.mask()) painter.drawPixmap(0, 0, pixmap)