本文整理汇总了Python中PyQt4.QtGui.QGraphicsOpacityEffect.opacity方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsOpacityEffect.opacity方法的具体用法?Python QGraphicsOpacityEffect.opacity怎么用?Python QGraphicsOpacityEffect.opacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsOpacityEffect
的用法示例。
在下文中一共展示了QGraphicsOpacityEffect.opacity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HiddenWidgetBase
# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import opacity [as 别名]
class HiddenWidgetBase(object):
INITIAL_TIMEOUT = 2000
NUM_STEPS = 15
INTERVAL = 20
def __init__(self, logger):
self.logger = logger
self.good = False
self.fadingEnabled = False
self.minOpacity = 0.
self.maxOpacity = 1.
self.incr = (self.maxOpacity - self.minOpacity) / self.NUM_STEPS
self.fadeIn = False
try:
from PyQt4.QtGui import QGraphicsOpacityEffect
self.effect = QGraphicsOpacityEffect(self)
self.setGraphicsEffect(self.effect)
self.timer = QTimer(self)
self.timer.timeout.connect(self._fade)
self.good = True
except:
self.logger.debug(u"Could not enable opacity effects. %s: %s", sys.exc_info()[0].__name__, unicode(sys.exc_info()[1]))
# cannot use loggingSlot here because this is no QObject
@loggingFunc
def setMinOpacity(self, newVal):
self.minOpacity = newVal
self.incr = (self.maxOpacity - self.minOpacity) / self.NUM_STEPS
if self.fadingEnabled and not self.timer.isActive():
self.timer.start(self.INTERVAL)
# cannot use loggingSlot here because this is no QObject
@loggingFunc
def setMaxOpacity(self, newVal):
self.maxOpacity = newVal
self.incr = (self.maxOpacity - self.minOpacity) / self.NUM_STEPS
if self.fadingEnabled and not self.timer.isActive():
self.timer.start(self.INTERVAL)
# cannot use loggingSlot here because this is no QObject
@loggingFunc
def showTemporarily(self):
if self.good:
self.fadingEnabled = False
self.fadeIn = False
self.timer.stop()
self.effect.setOpacity(self.maxOpacity)
QTimer.singleShot(self.INITIAL_TIMEOUT, self._fadeOut)
def _fadeOut(self):
self.fadingEnabled = True
self.timer.start(self.INTERVAL * 1.5)
# cannot use loggingSlot here because this is no QObject
@loggingFunc
def _fade(self):
if self.fadeIn:
desOp = self.maxOpacity
else:
desOp = self.minOpacity
opacity = self.effect.opacity()
if abs(opacity - desOp) < self.incr:
# prevent flickering if timer does not stop immediately
return
if opacity < desOp:
opacity += self.incr
self.effect.setOpacity(opacity)
else:
opacity -= self.incr
self.effect.setOpacity(opacity)
#finish animation if desired opacity is reached
if abs(opacity - desOp) < self.incr:
self.timer.stop()
def _mouseEntered(self):
if self.good and self.fadingEnabled:
self.fadeIn = True
self.timer.start(self.INTERVAL)
def _mouseLeft(self):
if self.good and self.fadingEnabled:
self.fadeIn = False
self.timer.start(self.INTERVAL)