當前位置: 首頁>>代碼示例>>Python>>正文


Python QGraphicsOpacityEffect.opacity方法代碼示例

本文整理匯總了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)
開發者ID:hannesrauhe,項目名稱:lunchinator,代碼行數:90,代碼來源:remote_pictures_gui.py


注:本文中的PyQt4.QtGui.QGraphicsOpacityEffect.opacity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。