def show_error(self):
     # 窗体抖动效果
     animation = QPropertyAnimation(self)
     animation.setTargetObject(self)
     animation.setPropertyName(b'pos')
     animation.setKeyValueAt(0, self.pos())
     animation.setKeyValueAt(0.2, self.pos() + QPoint(15, 0))
     animation.setKeyValueAt(0.5, self.pos())
     animation.setKeyValueAt(0.7, self.pos() + QPoint(-15, 0))
     animation.setKeyValueAt(1, self.pos())
     animation.setDuration(100)
     animation.setLoopCount(3)
     animation.start(QAbstractAnimation.DeleteWhenStopped)
示例#2
0
class FancyTab(QWidget):
    def __init__(self, tabbar):
        '''
        @param: tabbar QWidget
        '''
        super().__init__(tabbar)
        self.icon = QIcon()
        self.text = ''
        self._animator = QPropertyAnimation()
        self._tabbar = tabbar  # QWidget
        self._fader = 0.0

        self._animator.setPropertyName(b'fader')
        self._animator.setTargetObject(self)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)

    def fader(self):
        '''
        @return: float
        '''
        return self._fader

    def setFader(self, value):
        '''
        @param: value float
        '''
        self._fader = value
        self._tabbar.update()

    fader = pyqtProperty(float, fader, setFader)

    # override
    def sizeHint(self):
        '''
        @return: QSize
        '''
        boldFont = QFont(self.font())
        boldFont.setPointSizeF(styleHelper.sidebarFontSize())
        boldFont.setBold(True)
        fm = QFontMetrics(boldFont)
        spacing = 8
        width = 60 + spacing + 2
        iconHeight = 32
        ret = QSize(width, iconHeight + spacing + fm.height())
        return ret

    def fadeIn(self):
        self._animator.stop()
        self._animator.setDuration(80)
        self._animator.setEndValue(40)
        self._animator.start()

    def fadeOut(self):
        self._animator.stop()
        self._animator.setDuration(160)
        self._animator.setEndValue(0)
        self._animator.start()

    # protected:
    # override
    def enterEvent(self, event):
        self.fadeIn()

    # override
    def leaveEvent(self, event):
        self.fadeOut()