Hi, I'm still trying to wrap my head around events and trying to start an animated gif 'splashed' on a widget.
I can manage to detect when the mouse hovers in and out to display a start and stop but I can't seem to find how to trigger the movie.start() action.
I mashed up bits of code form other sites to display a window with an animated gif.
Any clues would be helpful...
from PySide import QtGui, QtCore
import PySide.QtCore as qc
import PySide.QtGui as qg
from PySide.QtCore import Signal,Slot
import sys, time
from PySide.QtCore import Qt, QTimer
from PySide.QtGui import *
import sys
from PySide.QtCore import *
from PySide.QtGui import *
class Window(QtGui.QWidget):
class MovieSplashScreen(QSplashScreen):
def __init__(self, movie, parent = None):
movie.jumpToFrame(0)
pixmap = QPixmap(movie.frameRect().size())
QSplashScreen.__init__(self, pixmap)
self.movie = movie
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)
def sizeHint(self):
return self.movie.scaledSize()
class animWidget(QtGui.QWidget):
mStart = Signal()
mStop = Signal()
zeros = 0
def __init__(self,parent=None):
QtGui.QWidget.__init__(self)
self._last_index = QtCore.QPersistentModelIndex()
self.installEventFilter(self)
def eventFilter(self, widget, event):
if event.type() == QtCore.QEvent.MouseMove:
print "Starting..."
self.mStart.emit()
self.startMovie()
self.emit(SIGNAL("mStart"))
elif event.type() == QtCore.QEvent.Leave:
print "Pausing"
self.mStop.emit()
return QtGui.QTableWidget.eventFilter(self, widget, event)
def startMovie(self,*args):
print "xxx"
#self.start()
def __init__(self, rows, columns):
QtGui.QWidget.__init__(self)
self.anim = self.animWidget(self)
self.anim.setMouseTracking(True)
self.animLayout = QtGui.QHBoxLayout()
self.anim.setLayout (self.animLayout)
layout = QtGui.QVBoxLayout(self)
movie = qg.QMovie("d:/cutebunny.gif")
self.movie = movie
splash = MovieSplashScreen(movie)
self.animGif = qg.QLabel(self)
self.animGif.setMovie(movie)
#self.movie.start()
self.animLayout.addWidget(self.animGif)
layout.addWidget(self.anim)
#self.movie.connect(SIGNAL("START"), self.startMovie)
#self.movie.connect(SIGNAL("mSTART"), self.startMovie)
if __name__ == '__main__':
import sys
#app = QtGui.QApplication(sys.argv)
window = Window(6, 3)
window.setGeometry(500, 300, 350, 250)
window.show()
#sys.exit(app.exec_())