class MyWidget(QtGui.QWidget):
def __init__(self)
self._visible = False
self._fadeInAniFinished = True
self._fadeOutAniFinished = True
self._fadeInAni = None
self._fadeOutAni = None
self._initAni()
def _initAni(self):
"""
初始化动画效果
:return:
"""
self._fadeInAni = QtCore.QPropertyAnimation(self, "windowOpacity")
self._fadeInAni.setDuration(100)
self._fadeInAni.setStartValue(0)
self._fadeInAni.setEndValue(1)
self._fadeInAni.finished.connect(self._setFadeInAniFinished)
self._fadeOutAni = QtCore.QPropertyAnimation(self, "windowOpacity")
self._fadeOutAni.setDuration(150)
self._fadeOutAni.setStartValue(1)
self._fadeOutAni.setEndValue(0)
self._fadeOutAni.finished.connect(self._setFadeOutAniFinished)
def setVisible(self, bool_visible):
"""
设置是否可见
:param bool_visible:
:return:
"""
self._visible = bool_visible
if bool_visible:
if not self._fadeOutAniFinished:
self._fadeOutAni.stop()
self._setFadeOutAniFinished()
if not self._fadeInAniFinished:
return
self._fadeInAniFinished = False
super(TipsWindow, self).setVisible(True)
self._fadeInAni.start()
else:
if not self._fadeInAniFinished:
self._fadeInAni.stop()
self._setFadeInAniFinished()
if not self._fadeOutAniFinished:
return
self._fadeOutAniFinished = False
self._fadeOutAni.start()
def isVisible(self):
"""
是否可见
:return:
"""
return self._visible
def _setFadeInAniFinished(self):
"""
淡入动画结束
:return:
"""
self._fadeInAniFinished = True
def _setFadeOutAniFinished(self):
"""
淡出动画结束
:return:
"""
super(TipsWindow, self).setVisible(False)
self._fadeOutAniFinished = True