My first impression is that almost all of the "setup" code here:
self.effect = QGraphicsOpacityEffect()
self.lblPhotoDisplay.setGraphicsEffect(self.effect )
self.animation = QtCore.QPropertyAnimation(self.effect, b"opacity")
self.animation.setDuration(1000)
self.animation.setStartValue(1)
self.animation.setEndValue(0)
self.animation.finished.connect(self.changeImage)
self.effect = QGraphicsOpacityEffect()
self.lblPhotoDisplay.setGraphicsEffect(self.effect )
self.animation = QtCore.QPropertyAnimation(self.effect, b"opacity")
self.animation.setDuration(1000)
self.animation.setStartValue(1)
self.animation.setEndValue(0)
self.animation.finished.connect(self.changeImage)
To copy to clipboard, switch view to plain text mode
should be in the __init__ method of your class. You do not need to create the animation, connect slots, etc. every time you want to fade or unfade. In __init__ you should create the animation, set the graphics effect, etc. and the only thing you do in the fade() and unfade() methods is to set the direction of the property change:
def __init__( self ) :
self.effect = QGraphicsOpacityEffect()
self.lblPhotoDisplay.setGraphicsEffect(self.effect )
self.animation = QtCore.QPropertyAnimation(self.effect, b"opacity")
self.animation.setDuration(1000)
self.animation.finished.connect(self.animationFinished)
self.fadeDirection = 0
def fade(self):
self.animation.setStartValue(1)
self.animation.setEndValue(0)
self.fadeDirection = 0
self.animation.start()
def unfade(self):
self.animation.setStartValue(0)
self.animation.setEndValue(1)
self.fadeDirection = 1
self.animation.start()
@Slot()
def animationFinished( self )
if self.fadeDirection == 0 :
self.changeImage()
else :
seld.nextImage()
def __init__( self ) :
self.effect = QGraphicsOpacityEffect()
self.lblPhotoDisplay.setGraphicsEffect(self.effect )
self.animation = QtCore.QPropertyAnimation(self.effect, b"opacity")
self.animation.setDuration(1000)
self.animation.finished.connect(self.animationFinished)
self.fadeDirection = 0
def fade(self):
self.animation.setStartValue(1)
self.animation.setEndValue(0)
self.fadeDirection = 0
self.animation.start()
def unfade(self):
self.animation.setStartValue(0)
self.animation.setEndValue(1)
self.fadeDirection = 1
self.animation.start()
@Slot()
def animationFinished( self )
if self.fadeDirection == 0 :
self.changeImage()
else :
seld.nextImage()
To copy to clipboard, switch view to plain text mode
The way your code is written, you are creating a new animation instance every time the fade() or unfade() methods are called and connecting that new instance to one of your two slots. Basically, you are creating two animation instances for every picture and building a rat's nest of signal / slot connections between them. Most QObject-based classes in Qt are generally best created once and reused, and signals and slots connected once, in a constructor.
Bookmarks