Python PyQt5.QtCore 模块,QPropertyAnimation() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用PyQt5.QtCore.QPropertyAnimation()

项目:MusicPlayer    作者:HuberTRoy    | 项目源码 | 文件源码
def getDetailInfo(self):
        """??????????: ???????????"""
        self.shortInfo.hide()
        self.detailInfo.show()

        self.showDetail = QPropertyAnimation(self, b"geometry")

        x = self.pos().x()
        y = self.pos().y()

        self.showDetail.setStartValue(QRect(x, y, self.width(), self.height()))
        # ???????????
        self.showDetail.setEndValue(QRect(0, self.grandparent.header.height()+3, self.grandparent.width(), self.grandparent.mainContent.height()))
        self.showDetail.setDuration(300)
        self.showDetail.setEasingCurve(QEasingCurve.InBack)

        self.showDetail.start(QAbstractAnimation.DeleteWhenStopped)
        # ??????????????????????
        self.raise_()

        self.setDetailInfo()
项目:MusicPlayer    作者:HuberTRoy    | 项目源码 | 文件源码
def getShortInfo(self):
        """????????????"""
        self.detailInfo.hide()
        self.showShort = QPropertyAnimation(self, b"geometry")

        x = self.pos().x()
        y = self.pos().y()

        self.showShort.setStartValue(QRect(0, self.grandparent.header.height(), self.grandparent.width(), self.grandparent.mainContent.height()))
        self.showShort.setEndValue(QRect(0, self.grandparent.height()-64-self.parent.height(), self.grandparent.navigation.width(), 64))
        self.showShort.setDuration(300)
        self.showShort.setEasingCurve(QEasingCurve.InBack)

        self.showShort.start(QAbstractAnimation.DeleteWhenStopped)

        self.shortInfo.show()
        self.raise_()
项目:pyplaybin    作者:fraca7    | 项目源码 | 文件源码
def startHiding(self):
        self._hideTimer = None
        if self._showState in [self.STATE_HIDING, self.STATE_HIDDEN]:
            return
        if self._showState == self.STATE_HIDING:
            self._showAnimation.stop()
        self._showState = self.STATE_HIDING
        self._showAnimation = QtCore.QPropertyAnimation(self, b'windowOpacity')
        self._showAnimation.setStartValue(self.windowOpacity())
        self._showAnimation.setEndValue(0.0)
        self._showAnimation.setDuration(500)
        self._showAnimation.finished.connect(self._showAnimationFinished)
        self._showAnimation.start()
项目:pyplaybin    作者:fraca7    | 项目源码 | 文件源码
def startShowing(self):
        if self._showState in [self.STATE_SHOWING, self.STATE_SHOWN]:
            return
        if self._showState == self.STATE_SHOWING:
            self._showAnimation.stop()
        self._showState = self.STATE_SHOWING
        self._showAnimation = QtCore.QPropertyAnimation(self, b'windowOpacity')
        self._showAnimation.setStartValue(self.windowOpacity())
        self._showAnimation.setEndValue(1.0)
        self._showAnimation.setDuration(500)
        self._showAnimation.finished.connect(self._showAnimationFinished)
        self._showAnimation.start()
项目:songscreen    作者:maccesch    | 项目源码 | 文件源码
def _update_screen_rect(self):
        if self._animation is not None and self._animation.state() == QAbstractAnimation.Running:
            return

        vertical_offset_bias = self._line_height - self._first_lyrics_line_y
        vertical_offset = self._scroll_progress * \
                          (self._document_height - len(self._extra_lines_after) * self._line_height)

        if vertical_offset <= vertical_offset_bias:
            vertical_offset = 0
        else:
            vertical_offset = min(vertical_offset - vertical_offset_bias, self._document_height)

        current_line_index = vertical_offset / self._line_height
        extra_line_count = len(tuple(filter(lambda i: i < current_line_index, self._extra_lines_after)))
        vertical_offset += self._line_height * extra_line_count

        diff = self.sceneRect().y() - vertical_offset
        if abs(diff) > self._line_height * self._line_increment:
            factor = -int(diff) // int(self._line_height * self._line_increment)
            y = self.sceneRect().y() + (self._line_height * self._line_increment) * factor
            y = max(0, y)
            target_rect = QRectF(0, y, self.w, self.h)

            if not self._covered:
                self._animation = QPropertyAnimation(self, b"sceneRect")
                self._animation.setDuration(3000)
                self._animation.setStartValue(self.sceneRect())
                self._animation.setEndValue(target_rect)
                self._animation.setEasingCurve(QEasingCurve.InOutQuad)
                self._animation.start()
            else:
                self._animation = None
                self.setSceneRect(target_rect)
项目:songscreen    作者:maccesch    | 项目源码 | 文件源码
def fade_in(self):
        self.show()
        self.raise_()
        self._covered = False

        self._document_cover_animation = QPropertyAnimation(self._document_cover, b"opacity")

        self._document_cover_animation.setDuration(1000)
        self._document_cover_animation.setStartValue(1)
        self._document_cover_animation.setEndValue(0)
        self._document_cover_animation.setEasingCurve(QEasingCurve.InOutQuad)
        self._document_cover_animation.start()
项目:songscreen    作者:maccesch    | 项目源码 | 文件源码
def fade_out(self):
        self._document_cover_animation = QPropertyAnimation(self._document_cover, b"opacity")

        self._document_cover_animation.finished.connect(self._fade_out_finished)

        self._document_cover_animation.setDuration(1000)
        self._document_cover_animation.setStartValue(0)
        self._document_cover_animation.setEndValue(1)
        self._document_cover_animation.setEasingCurve(QEasingCurve.InOutQuad)
        self._document_cover_animation.start()
项目:srpdfcrawler    作者:DeastinY    | 项目源码 | 文件源码
def __init__(self, parent=None, title='', animation_duration=300):
        """
        References:
            # Adapted from c++ version
            http://stackoverflow.com/questions/32476006/how-to-make-an-expandable-collapsable-section-widget-in-qt
        """
        super(GroupWidget, self).__init__(parent=parent)

        self.animation_duration = animation_duration
        self.toggle_animation = QParallelAnimationGroup()
        self.content_area = QScrollArea()
        self.header_line = QFrame()
        self.toggle_button = QToolButton()
        self.main_layout = QGridLayout()

        toggle_button = self.toggle_button
        toggle_button.setStyleSheet("QToolButton { border: none; }")
        toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        toggle_button.setArrowType(Qt.RightArrow)
        toggle_button.setText(str(title))
        toggle_button.setCheckable(True)
        toggle_button.setChecked(False)

        header_line = self.header_line
        header_line.setFrameShape(QFrame.HLine)
        header_line.setFrameShadow(QFrame.Sunken)
        header_line.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)

        self.content_area.setStyleSheet("QScrollArea { background-color: white; border: none; }")
        self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        # start out collapsed
        self.content_area.setMaximumHeight(0)
        self.content_area.setMinimumHeight(0)
        # let the entire widget grow and shrink with its content
        toggle_animation = self.toggle_animation
        toggle_animation.addAnimation(QPropertyAnimation(self, bytes("minimumHeight", "utf-8")))
        toggle_animation.addAnimation(QPropertyAnimation(self, bytes("maximumHeight", "utf-8")))
        toggle_animation.addAnimation(QPropertyAnimation(self.content_area, bytes("maximumHeight", "utf-8")))
        # don't waste space
        main_layout = self.main_layout
        main_layout.setVerticalSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)
        row = 0
        main_layout.addWidget(self.toggle_button, row, 0, 1, 1, Qt.AlignLeft)
        main_layout.addWidget(self.header_line, row, 2, 1, 1)
        row += 1
        main_layout.addWidget(self.content_area, row, 0, 1, 3)
        self.setLayout(self.main_layout)

        def start_animation(checked):
            arrow_type = Qt.DownArrow if checked else Qt.RightArrow
            direction = QAbstractAnimation.Forward if checked else QAbstractAnimation.Backward
            toggle_button.setArrowType(arrow_type)
            self.toggle_animation.setDirection(direction)
            self.toggle_animation.start()

        self.toggle_button.clicked.connect(start_animation)