def createAnimation(self, target, index): '''创建动画''' # 暂停动画一 PauseAnimation1 = QPauseAnimation(target) PauseAnimation1.setDuration(150 * index) # 并行动画组一 # #透明度动画一 OpacityAnimation1 = QPropertyAnimation(target, b"opacity") OpacityAnimation1.setDuration(400) OpacityAnimation1.setStartValue(0) OpacityAnimation1.setEndValue(1) # #移动动画一 MoveAnimation1 = _MoveAnimation(target, self.parent, self.easing) MoveAnimation1.setMoveType(_MoveAnimation.MOVE1) MoveAnimation1.setDuration(400) MoveAnimation1.setStartValue(QPoint(0, 0)) MoveAnimation1.setEndValue(QPoint(self.parent.width() / 4.0, 0)) # 添加到并行动画里面 ParallelAnimation1 = QParallelAnimationGroup() ParallelAnimation1.addAnimation(OpacityAnimation1) ParallelAnimation1.addAnimation(MoveAnimation1) # 移动动画二 MoveAnimation2 = _MoveAnimation(target, self.parent, self.easing) MoveAnimation2.setMoveType(_MoveAnimation.MOVE2) MoveAnimation2.setDuration(2000) MoveAnimation2.setEndValue(QPoint((self.parent.width() / 4.0) * 3.0, 0)) # 并行动画组二 # #透明度动画二 OpacityAnimation2 = QPropertyAnimation(target, b"opacity") OpacityAnimation2.setDuration(400) OpacityAnimation2.setStartValue(1) OpacityAnimation2.setEndValue(0) # #移动动画三 MoveAnimation3 = _MoveAnimation(target, self.parent, self.easing) MoveAnimation3.setMoveType(_MoveAnimation.MOVE3) MoveAnimation3.setDuration(400) MoveAnimation3.setEndValue(QPoint(self.parent.width(), 0)) # 添加到并行动画里面 ParallelAnimation2 = QParallelAnimationGroup() ParallelAnimation2.addAnimation(OpacityAnimation2) ParallelAnimation2.addAnimation(MoveAnimation3) # 暂停动画二 PauseAnimation2 = QPauseAnimation(target) PauseAnimation2.setDuration(150 * (5 - index - 1)) # 串行动画组 self.setLoopCount(-1) # 无限循环 self.addAnimation(PauseAnimation1) self.addAnimation(ParallelAnimation1) self.addAnimation(MoveAnimation2) self.addAnimation(ParallelAnimation2) self.addAnimation(PauseAnimation2)
def start(self): bh = self.height() / 2 - self._ball_radius width = self.width() for i in range(self._ball_numbers): self._seq_animations.append(QSequentialAnimationGroup(self)) # 增加间隔 self._seq_animations[i].addPause(self.duration_pause * i) # 第一段 par_animation1 = QParallelAnimationGroup(self) pa = QPropertyAnimation(self._balls[i], b'pos', self) pa.setEasingCurve(self._ec1) pa.setDuration(self.duration * self._first_flag) pa.setStartValue(QPoint(0, bh)) pa.setEndValue(QPoint(width * 0.4, bh)) par_animation1.addAnimation(pa) pa = QPropertyAnimation(self._balls[i], b'_style', self) pa.setEasingCurve(self._ec1) pa.setDuration(self.duration * self._first_flag) pa.setStartValue(0) pa.setEndValue(255) par_animation1.addAnimation(pa) self._seq_animations[i].addAnimation(par_animation1) # 第二段 pa = QPropertyAnimation(self._balls[i], b'pos', self) pa.setDuration(self.duration * self._second_flag) pa.setStartValue(QPoint(width * 0.4, bh)) pa.setEndValue(QPoint(width * 0.6, bh)) self._seq_animations[i].addAnimation(pa) # 第三段 par_animation2 = QParallelAnimationGroup(self) pa = QPropertyAnimation(self._balls[i], b'pos', self) pa.setEasingCurve(self._ec2) pa.setDuration(self.duration * self._three_flag) pa.setStartValue(QPoint(width * 0.6, bh)) pa.setEndValue(QPoint(width, bh)) par_animation2.addAnimation(pa) pa = QPropertyAnimation(self._balls[i], b'_style', self) pa.setEasingCurve(self._ec2) pa.setDuration(self.duration * self._three_flag) pa.setStartValue(255) pa.setEndValue(0) par_animation2.addAnimation(pa) self._seq_animations[i].addAnimation(par_animation2) # 增加间隔 self._seq_animations[i].addPause(self.duration_pause * (self._ball_numbers - i - 1)) for seq in self._seq_animations: seq.setLoopCount(-1) seq.start(QAbstractAnimation.DeleteWhenStopped)
def fin(pix): ## delete pixitem node = Node(pix) node.pix.setOriginPt() sync = random.randint(6, 10) * 75 rot = 270 if not random.randint(0, 1): rot = -270 rotate = QPropertyAnimation(node, b'rotate') rotate.setDuration(sync) rotate.setStartValue(node.pix.rotation) rotate.setEndValue(rot + node.pix.rotation) opacity = QPropertyAnimation(node, b'opacity') opacity.setDuration(sync) opacity.setStartValue(node.pix.opacity()) opacity.setEndValue(0) scale = QPropertyAnimation(node, b'scale') scale.setDuration(sync) scale.setStartValue(node.pix.scale) scale.setEndValue(node.pix.scale * .25) group = QParallelAnimationGroup() group.addAnimation(rotate) group.addAnimation(opacity) group.addAnimation(scale) group.setLoopCount(1) return group
def __createAlbumCards(self): """ 将专辑卡添加到窗口中 """ # 创建并行动画组 self.hideCheckBoxAniGroup = QParallelAnimationGroup(self) self.hideCheckBoxAni_list = [] for albumInfo in self.albumInfo_list: self.__createOneAlbumCard(albumInfo)
def reprise(pix): ## reposition pixitems to starting x,y, etc. node = Node(pix) node.pix.setOriginPt() sync = 1000 reprise = QPropertyAnimation(node, b'pos') reprise.setDuration(sync) reprise.setStartValue(node.pix.pos()) reprise.setEndValue(QPointF(pix.x, pix.y)) spin = QPropertyAnimation(node, b'rotate') spin.setDuration(sync) spin.setStartValue(node.pix.rotation) spin.setKeyValueAt(0.50, pix.rotation + random.randint(15, 45)) spin.setEndValue(pix.rotation) scale = QPropertyAnimation(node, b'scale') scale.setDuration(sync) scale.setStartValue(node.pix.scale) scale.setEndValue(pix.scale) opacity = QPropertyAnimation(node, b'opacity') opacity.setDuration(sync) opacity.setStartValue(node.pix.opacity()) opacity.setEndValue(1) group = QParallelAnimationGroup() group.addAnimation(reprise) group.addAnimation(spin) group.addAnimation(scale) group.addAnimation(opacity) return group
def addWidget(self, widget, deltaX: int = 0, deltaY: int = 22, isNeedOpacityAni=True): """ 添加堆叠窗口\n Parameters ----------- widget : 窗口\n deltaX : 窗口动画开始到结束的x轴偏移量\n deltaY : 窗口动画开始到结束的y轴偏移量\n isNeedOpacityAni : 是否需要淡入淡出动画\n """ super().addWidget(widget) # 创建动画 popUpAni = QPropertyAnimation(widget, b'geometry') aniGroup = QParallelAnimationGroup(self) aniGroup.addAnimation(popUpAni) self.__widgetAni_list.append({ 'widget': widget, 'deltaX': deltaX, 'deltaY': deltaY, 'aniGroup': aniGroup, 'popUpAni': popUpAni, 'isNeedOpacityAni': isNeedOpacityAni })
def __init__(self, playlist: list = None, parent=None): super().__init__(parent) self.playlist = playlist.copy() self.currentIndex = 0 self.isPlaylistVisible = False # 创建小部件 self.blurPixmap = None self.blurBackgroundPic = QLabel(self) self.blurCoverThread = BlurCoverThread(self) self.songInfoCardChute = SongInfoCardChute(self, self.playlist) self.parallelAniGroup = QParallelAnimationGroup(self) self.songInfoCardChuteAni = QPropertyAnimation(self.songInfoCardChute, b'geometry') self.playBar = PlayBar(self) self.songListWidget = SongListWidget(self.playlist, self) self.smallestModeInterface = SmallestPlayModeInterface(playlist, self) self.playBarAni = QPropertyAnimation(self.playBar, b'geometry') self.songListWidgetAni = QPropertyAnimation(self.songListWidget, b'geometry') self.guideLabel = QLabel('在这里,你将看到正在播放的歌曲以及即将播放的歌曲。', self) self.randomPlayAllButton = ThreeStateButton( { 'normal': r'resource\images\playing_interface\全部随机播放_normal_256_39.png', 'hover': r'resource\images\playing_interface\全部随机播放_hover_256_39.png', 'pressed': r'resource\images\playing_interface\全部随机播放_pressed_256_39.png' }, self, (256, 39)) # 创建定时器 self.showPlaylistTimer = QTimer(self) self.hidePlaylistTimer = QTimer(self) # 初始化 self.__initWidget()
def _initAnimations(self): '''动画效果''' if hasattr(self, "_animationGroup"): return # 由于showEvent的关系,这里要防止多次实例化 self._animationGroup = QParallelAnimationGroup(self) # 并行动画 # 标题栏 self._animationTitleBar = QPropertyAnimation( self._titleBar, b"geometry", self, easingCurve=QEasingCurve.OutBounce, duration=1000) # 菜单栏 self._animationMenuWidget = QPropertyAnimation( self._menuWidget, b"geometry", self, easingCurve=QEasingCurve.OutBounce, duration=1000) # 链接 self._animationLinkWidget = QPropertyAnimation( self._linkWidget, b"geometry", self, easingCurve=QEasingCurve.OutBounce, duration=1000) # 内容 self._animationContentWidget = QPropertyAnimation( self._contentWidget, b"geometry", self, easingCurve=QEasingCurve.OutBounce, duration=1000) # add to group self._animationGroup.addAnimation(self._animationTitleBar) self._animationGroup.addAnimation(self._animationMenuWidget) self._animationGroup.addAnimation(self._animationLinkWidget) self._animationGroup.addAnimation(self._animationContentWidget) # 初始化位置 self._initAnimationsValues(True) # 启动动画效果 self._animationGroup.start()
def __init__(self, orientation=Orientation.HORIZONTAL, animationDuration=120, parent=None): QWidget.__init__(self, parent) self.opened = False self.orientation = orientation self.animationDuration = animationDuration self.mainLayout = None self.animator = QParallelAnimationGroup() if orientation is self.Orientation.HORIZONTAL: self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.setMaximumWidth(0) self.setMinimumWidth(0) # let the entire widget grow and shrink with its content self.animator.addAnimation(QPropertyAnimation(self)) self.animator.addAnimation( QPropertyAnimation(self, b"minimumWidth")) self.animator.addAnimation( QPropertyAnimation(self, b"maximumWidth")) elif orientation is self.Orientation.VERTICAL: self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.setMaximumHeight(0) self.setMinimumHeight(0) # let the entire widget grow and shrink with its content self.animator.addAnimation(QPropertyAnimation(self)) self.animator.addAnimation( QPropertyAnimation(self, b"minimumHeight")) self.animator.addAnimation( QPropertyAnimation(self, b"maximumHeight"))
def __init__(self, playlist: list = None, parent=None): super().__init__(parent) self.playlist = playlist.copy() self.currentIndex = 0 self.isPlaylistVisible = False # 创建小部件 self.blurPixmap = None self.blurBackgroundPic = QLabel(self) self.blurCoverThread = BlurCoverThread(self) self.songInfoCardChute = SongInfoCardChute(self, self.playlist) self.parallelAniGroup = QParallelAnimationGroup(self) self.songInfoCardChuteAni = QPropertyAnimation(self.songInfoCardChute, b"geometry") self.playBar = PlayBar(self) self.songListWidget = SongListWidget(self.playlist, self) self.smallestModeInterface = SmallestPlayModeInterface(playlist, self) self.playBarAni = QPropertyAnimation(self.playBar, b"geometry") self.songListWidgetAni = QPropertyAnimation(self.songListWidget, b"geometry") self.guideLabel = QLabel("在这里,你将看到正在播放的歌曲以及即将播放的歌曲。", self) self.randomPlayAllButton = ThreeStatePushButton( { "normal": r"app\resource\images\playing_interface\全部随机播放_normal.png", "hover": r"app\resource\images\playing_interface\全部随机播放_hover.png", "pressed": r"app\resource\images\playing_interface\全部随机播放_pressed.png", }, " 随机播放你收藏中的所有内容", (30, 22), self) # 创建定时器 self.showPlaylistTimer = QTimer(self) self.hidePlaylistTimer = QTimer(self) # 初始化 self.__initWidget()
def start(self): height = self.height() width = self.width() for i in range(self._ball_numbers): self._seq_animations.append(QSequentialAnimationGroup(self)) # 增加间隔 self._seq_animations[i].addPause(self.duration_pause * i) # 第一段 par_animation1 = QParallelAnimationGroup(self) ra = RoundAnimation(self._balls[i], b'pos', self) ra.setEasingCurve(self.ec) ra.setDuration(self.duration) ra.setStartValue(QPoint(2 * self.ball_radius, 2 * self.ball_radius)) ra.setEndValue(QPoint(width - 2 * self.ball_radius, height - 2 * self.ball_radius)) par_animation1.addAnimation(ra) pa = QPropertyAnimation(self._balls[i], b'_style', self) pa.setEasingCurve(self.ec) pa.setDuration(self.duration) pa.setStartValue(0) pa.setKeyValueAt(0.5, 255) pa.setEndValue(0) par_animation1.addAnimation(pa) self._seq_animations[i].addAnimation(par_animation1) # 增加间隔 self._seq_animations[i].addPause(self.duration_pause * (self._ball_numbers - i - 1)) for seq in self._seq_animations: seq.setLoopCount(-1) seq.start(QAbstractAnimation.DeleteWhenStopped)
def step_ani(self, is_back=False): title_move_ani, title_fade_ani = self.fade_to_left_ani(self.title) content1_move_ani, content1_fade_ani = self.fade_to_left_ani( self.content1) content2_move_ani, content2_fade_ani = self.fade_to_left_ani( self.content2) form_move_ani, form_fade_ani = self.fade_to_left_ani(self.form) # 动画队列 ani_group = QParallelAnimationGroup(self) ani_group.addAnimation(title_move_ani) ani_group.addAnimation(title_fade_ani) ani_group.addAnimation(content1_move_ani) ani_group.addAnimation(content1_fade_ani) ani_group.addAnimation(content2_move_ani) ani_group.addAnimation(content2_fade_ani) ani_group.addAnimation(form_move_ani) ani_group.addAnimation(form_fade_ani) if is_back: ani_group.setDirection(ani_group.Backward) ani_group.start() return ani_group
def setupUi(self, popup_post): super().setupUi(popup_post) self.setAttribute(Qt.WA_TranslucentBackground) desktop = QApplication.desktop() self.move(desktop.width() - 50 - self.width(), desktop.height() - 300 - self.height()) # 因为带浏览器的透明窗口不能渲染,浏览器放在独立窗口 self.content_view = WeiboWebView(self) self.content_view.setWindowOpacity(0) # 淡出淡入动画 self._window_fade_anim = QPropertyAnimation(self, b'windowOpacity', self) self._window_fade_anim.setDuration(300) self._window_fade_anim.setStartValue(0) self._window_fade_anim.setEndValue(0.5) self._content_fade_anim = QPropertyAnimation(self.content_view, b'windowOpacity', self) self._content_fade_anim.setDuration(300) self._content_fade_anim.setStartValue(0) self._content_fade_anim.setEndValue(0.7) self._fade_anim_group = QParallelAnimationGroup(self) self._fade_anim_group.addAnimation(self._window_fade_anim) self._fade_anim_group.addAnimation(self._content_fade_anim) self._fade_anim_group.finished.connect(self._on_anim_finish)
def __createPlaylistCards(self): """ 创建播放列表卡 """ # 创建并行动画组 self.hideCheckBoxAniGroup = QParallelAnimationGroup(self) self.hideCheckBoxAni_list = [] for playlist in self.playlists: self.__createOnePlaylistCard(playlist)
def __init__(self, title="", parent=None): super(CollapsibleBox, self).__init__(parent) self.toggle_button = QToolButton(text=title, checkable=True, checked=False) self.toggle_button.setStyleSheet("QToolButton { border: none; }") self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.toggle_button.setArrowType(Qt.RightArrow) self.toggle_button.pressed.connect(self.on_pressed) self.toggle_animation = QParallelAnimationGroup(self) self.content_area = QScrollArea(maximumHeight=0, minimumHeight=0) self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.content_area.setFrameShape(QFrame.NoFrame) lay = QVBoxLayout(self) lay.setSpacing(0) lay.setContentsMargins(0, 0, 0, 0) lay.addWidget(self.toggle_button) lay.addWidget(self.content_area) self.toggle_animation.addAnimation( QPropertyAnimation(self, b"minimumHeight")) self.toggle_animation.addAnimation( QPropertyAnimation(self, b"maximumHeight")) self.toggle_animation.addAnimation( QPropertyAnimation(self.content_area, b"maximumHeight"))
def __init__(self, playlist: list, parent=None): super().__init__(parent) self.playlist = playlist self.currentIndex = 0 self.shiftLeftTime = 0 self.shiftRightTime = 0 self.songInfoCard_list = [] self.__unCompleteShift_list = [] # 创建按钮 self.playButton = PlayButton( [ r"app\resource\images\smallest_play_mode\播放_45_45.png", r"app\resource\images\smallest_play_mode\暂停_45_45.png", ], self, ) self.lastSongButton = SmallestPlayModeButton( r"app\resource\images\smallest_play_mode\上一首_45_45.png", self) self.nextSongButton = SmallestPlayModeButton( r"app\resource\images\smallest_play_mode\下一首_45_45.png", self) self.exitSmallestModeButton = BasicCircleButton( r"app\resource\images\playing_interface\最小模式播放_47_47.png", self) self.progressBar = QSlider(Qt.Horizontal, self) self.aniGroup = QParallelAnimationGroup(self) # 创建歌曲信息卡 self.__createSongInfoCards() # 初始化 self.__initWidget()
def rain(pix, node): node.pix.setOriginPt() pos = node.pix.pos() sync = random.randint(17, 31) * 50 y = int(pos.y()) ViewH = common["ViewH"] bottom = y + ViewH + node.pix.height * 2 top = y + node.pix.height * 2 rain1 = QPropertyAnimation(node, b'pos') rain1.setDuration(sync) rain1.setStartValue(pos) rain1.setEndValue(pos + QPointF(0, bottom)) opacity1 = QPropertyAnimation(node, b'opacity') opacity1.setDuration(sync) opacity1.setStartValue(node.pix.opacity()) opacity1.setKeyValueAt(.10, .50) opacity1.setEndValue(0) par1 = QParallelAnimationGroup() par1.addAnimation(rain1) par1.addAnimation(opacity1) rain2 = QPropertyAnimation(node, b'pos') rain2.setDuration(sync) rain2.setStartValue(pos + QPointF(0, -top)) rain2.setEndValue(pos) opacity2 = QPropertyAnimation(node, b'opacity') opacity2.setDuration(sync) opacity2.setStartValue(node.pix.opacity()) opacity2.setEndValue(.85) par2 = QParallelAnimationGroup() par2.addAnimation(rain2) par2.addAnimation(opacity2) rain = QSequentialAnimationGroup() rain.addAnimation(par1) rain.addAnimation(par2) rain.setLoopCount(-1) return rain
def __init__(self, songInfo: dict, songCardType, parent=None): """ 实例化歌曲卡 Parameters ---------- songInfo: dict 歌曲信息字典 songCardType: `~SongCardType` 歌曲卡类型 parent: 父级 """ super().__init__(parent) self._getInfo(songInfo) self.__resizeTime = 0 self.__songCardType = songCardType # 歌曲卡类型 self.__SongNameCard = [SongTabSongNameCard, TrackNumSongNameCard][songCardType.value] # 初始化各标志位 self.isSongExist = True self.isPlaying = False self.isSelected = False self.isChecked = False self.isInSelectionMode = False self.isDoubleClicked = False # 记录songCard对应的item的下标 self.itemIndex = None # 创建小部件 if self.__songCardType == SongCardType.SONG_TAB_SONG_CARD: self.songNameCard = self.__SongNameCard(self.songName, self) elif self.__songCardType == SongCardType.ALBUM_INTERFACE_SONG_CARD: self.songNameCard = self.__SongNameCard(self.songName, self.tracknumber, self) self.__referenceWidgets() # 初始化小部件列表 self.__scaleableLabelTextWidth_list = [] # 可拉伸的标签的文本的宽度列表 self.__scaleableWidgetMaxWidth_list = [] # 可拉伸部件的最大宽度列表 self.__dynamicStyleLabel_list = [] self.__scaleableWidget_list = [] self.__clickableLabel_list = [] self.__labelSpacing_list = [] self.__label_list = [] self.__widget_list = [] # 存放所有的小部件 # 创建动画组和动画列表 self.aniGroup = QParallelAnimationGroup(self) self.__aniWidget_list = [] self.__deltaX_list = [] self.ani_list = [] # 安装事件过滤器 self.installEventFilter(self) # 信号连接到槽 self.playButton.clicked.connect(self.playButtonSlot) self.addToButton.clicked.connect(self.__showAddToMenu) self.checkBox.stateChanged.connect(self.checkedStateChangedSlot)
def __init__(self, parent=None): super(SlidingStackedWidget, self).__init__(parent) self.animationEasingCurve = QEasingCurve.Linear self.animationDuration = 250 self.verticalMode = False self.wrap = False self._active = False self._animation_group = QParallelAnimationGroup() self._animation_group.finished.connect(self._SH_AnimationGroupFinished)
def _initAnimations(self): for index in range(5): # 5个小圆 item = CircleItem(self) item.valueChanged.connect(self.update) # 串行动画组 seqAnimation = QSequentialAnimationGroup(self) seqAnimation.setLoopCount(-1) self._items.append((item, seqAnimation)) # 暂停延迟动画 seqAnimation.addAnimation(QPauseAnimation(150 * index, self)) # 加速,并行动画组1 parAnimation1 = QParallelAnimationGroup(self) # 透明度 parAnimation1.addAnimation(QPropertyAnimation( item, b'opacity', self, duration=400, startValue=0, endValue=1.0)) # x坐标 parAnimation1.addAnimation(QPropertyAnimation( item, b'x', self, duration=400, startValue=0, endValue=25.0)) seqAnimation.addAnimation(parAnimation1) ## # 匀速 seqAnimation.addAnimation(QPropertyAnimation( item, b'x', self, duration=2000, startValue=25.0, endValue=75.0)) # 加速,并行动画组2 parAnimation2 = QParallelAnimationGroup(self) # 透明度 parAnimation2.addAnimation(QPropertyAnimation( item, b'opacity', self, duration=400, startValue=1.0, endValue=0)) # x坐标 parAnimation2.addAnimation(QPropertyAnimation( item, b'x', self, duration=400, startValue=75.0, endValue=100.0)) seqAnimation.addAnimation(parAnimation2) ## # 暂停延迟动画 seqAnimation.addAnimation( QPauseAnimation((5 - index - 1) * 150, self)) for _, animation in self._items: animation.start()
def login_animate(parent, color): parent.parallel_animation_group = QParallelAnimationGroup() parent.anim = None for i in range(4): parent.anim = QPropertyAnimation(parent.pieces[color][i], b"geometry") parent.anim.setDuration(1000) parent.anim.setEndValue(parent.bases[color][i].geometry()) parent.parallel_animation_group.addAnimation(parent.anim) parent.parallel_animation_group.start()
def __init__(self, header, normal_icon="", hovered_icon="", selected_icon=""): QWidget.__init__(self) self.is_expanded = False self.text = header self.label_normal_color = self.palette().link().color().name() self.label_hovered_color = self.palette().highlight().color().name() self.label_selected_color = self.palette().highlightedText().color().name() self.normal_color = self.palette().base().color().name() self.selected_color = self.palette().highlight().color() self.hovered_color = self.palette().alternateBase().color() self.setCursor(Qt.PointingHandCursor) if normal_icon: self.normal_icon = QImage(normal_icon) if hovered_icon: self.hovered_icon = QImage(hovered_icon) if selected_icon: self.selected_icon = QImage(selected_icon) self.setAttribute(Qt.WA_Hover, True) self.color = self.normal_color self.setAutoFillBackground(True) vbox = QVBoxLayout() hbox = QHBoxLayout() self.icon = QLabel() self.icon.setPixmap(QPixmap.fromImage(self.normal_icon)) self.hyper = QLabel() self.hyper.setText("<a style=\"color: " + self.label_normal_color + " text-decoration: none\" href=\"#\">" + self.text + "</a>") hbox.addWidget(self.icon) hbox.addSpacing(5) hbox.addWidget(self.hyper) hbox.addStretch() hbox.setContentsMargins(8, 8, 8, 8) vbox.addLayout(hbox) self.content = QWidget() self.content.setStyleSheet("background-color: " + self.palette().base().color().name()) self.content.setMaximumHeight(0) vbox.addWidget(self.content) vbox.setContentsMargins(0, 0, 0, 0) self.setLayout(vbox) self.hyper.linkActivated.connect(self.buttonClicked) self.anim = QParallelAnimationGroup() self.height_anim = QPropertyAnimation(self.content, "maximumHeight".encode("utf-8")) self.color_anim = QPropertyAnimation(self, "color".encode("utf-8")) self.height_anim.setDuration(200) self.color_anim.setDuration(200) self.anim.addAnimation(self.height_anim) self.anim.addAnimation(self.color_anim)
def __init__(self, Title="", parent=None, defaultLayout=False, Message=None): super().__init__(parent) self.toggle_button = QToolButton(text=Title, checkable=True, checked=False) self.toggle_button.setStyleSheet("QToolButton { border: none; }") self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.toggle_button.setArrowType(Qt.RightArrow) self.toggle_button.pressed.connect(self.on_pressed) self.toggle_animation = QParallelAnimationGroup(self) self.content_area = QScrollArea(maximumHeight=0, minimumHeight=0) self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.content_area.setFrameShape(QFrame.NoFrame) lay = QVBoxLayout(self) lay.setSpacing(0) lay.setContentsMargins(0, 0, 0, 0) lay.addWidget(self.toggle_button) lay.addWidget(self.content_area) self.toggle_animation.addAnimation( QPropertyAnimation(self, b"minimumHeight")) self.toggle_animation.addAnimation( QPropertyAnimation(self, b"maximumHeight")) self.toggle_animation.addAnimation( QPropertyAnimation(self.content_area, b"maximumHeight")) if defaultLayout: lay = QVBoxLayout() self.text = QLabel() pa = QPalette() pa.setColor(pa.Background, Qt.white) pa.setColor(pa.Foreground, Qt.black) self.text.setAutoFillBackground(True) self.text.setPalette(pa) self.text.setTextInteractionFlags(Qt.TextSelectableByMouse) self.text.setTextFormat(Qt.MarkdownText) self.text.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) self.text.setWordWrap(True) if not Message: Message = '空' self.text.setText(Message.replace('\n', '\n\n') + '\n') lay.addWidget(self.text) self.setContentLayout(lay)
def __init__(self, stickMan, keyReceiver): self.m_stickMan = stickMan self.m_keyReceiver = keyReceiver # Create animation group to be used for all transitions. self.m_animationGroup = QParallelAnimationGroup() stickManNodeCount = self.m_stickMan.nodeCount() self._pas = [] for i in range(stickManNodeCount): pa = QPropertyAnimation(self.m_stickMan.node(i), 'pos') self._pas.append(pa) self.m_animationGroup.addAnimation(pa) # Set up intial state graph. self.m_machine = QStateMachine() self.m_machine.addDefaultAnimation(self.m_animationGroup) self.m_alive = QState(self.m_machine) self.m_alive.setObjectName('alive') # Make it blink when lightning strikes before entering dead animation. lightningBlink = QState(self.m_machine) lightningBlink.assignProperty(self.m_stickMan.scene(), 'backgroundBrush', Qt.white) lightningBlink.assignProperty(self.m_stickMan, 'penColor', Qt.black) lightningBlink.assignProperty(self.m_stickMan, 'fillColor', Qt.white) lightningBlink.assignProperty(self.m_stickMan, 'isDead', True) timer = QTimer(lightningBlink) timer.setSingleShot(True) timer.setInterval(100) lightningBlink.entered.connect(timer.start) lightningBlink.exited.connect(timer.stop) self.m_dead = QState(self.m_machine) self.m_dead.assignProperty(self.m_stickMan.scene(), 'backgroundBrush', Qt.black) self.m_dead.assignProperty(self.m_stickMan, 'penColor', Qt.white) self.m_dead.assignProperty(self.m_stickMan, 'fillColor', Qt.black) self.m_dead.setObjectName('dead') # Idle state (sets no properties). self.m_idle = QState(self.m_alive) self.m_idle.setObjectName('idle') self.m_alive.setInitialState(self.m_idle) # Lightning strikes at random. self.m_alive.addTransition(LightningStrikesTransition(lightningBlink)) lightningBlink.addTransition(timer.timeout, self.m_dead) self.m_machine.setInitialState(self.m_alive)
def __init__(self, title="", parent=None, animation_duration=300): """ References: # Adapted from c++ version http://stackoverflow.com/questions/32476006/how-to-make-an-expandable-collapsable-section-widget-in-qt """ super(CollapsibleWidget, self).__init__(parent) self.title = title self.toggle_button = QToolButton() self.toggle_animation = QParallelAnimationGroup(self) self.content_area = QScrollArea() self.animation_duration = animation_duration self._init_base_ui()
def __init__(self, parent=None): QWidget.__init__(self, parent) self.mainLayout = QGridLayout() self.toggleButton = QToolButton() self.toggleAnimation = QParallelAnimationGroup() self.contentArea = QScrollArea() self.headerLine = QFrame() self.animationDuration = 300 self.checked = False self.toggleButton.setStyleSheet("QToolButton { border: none; }") self.toggleButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.toggleButton.setArrowType(Qt.ArrowType.RightArrow) self.toggleButton.setText("Title") self.toggleButton.setCheckable(True) self.toggleButton.setChecked(False) self.headerLine.setFrameShape(QFrame.HLine) self.headerLine.setFrameShadow(QFrame.Sunken) self.headerLine.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) self.contentArea.setStyleSheet( "QScrollArea { background-color: white; border: none; }") self.contentArea.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.contentArea.setMaximumHeight(0) self.contentArea.setMinimumHeight(0) # let the entire widget grow and shrink with its content self.toggleAnimation.addAnimation(QPropertyAnimation()) self.toggleAnimation.addAnimation(QPropertyAnimation(self)) self.toggleAnimation.addAnimation( QPropertyAnimation(self, b"minimumHeight")) self.toggleAnimation.addAnimation( QPropertyAnimation(self, b"maximumHeight")) self.toggleAnimation.addAnimation( QPropertyAnimation(self.contentArea, b"maximumHeight")) # don't waste space self.mainLayout.setVerticalSpacing(0) self.mainLayout.setContentsMargins(0, 0, 0, 0) row = 0 self.mainLayout.addWidget(self.toggleButton, 0, 0, 1, 1, Qt.AlignLeft) self.mainLayout.addWidget(self.headerLine, 0, 2, 1, 1) self.mainLayout.addWidget(self.contentArea, 1, 0, 1, 3) self.setLayout(self.mainLayout) self.toggleButton.clicked.connect(self, SLOT("onBtnClicked(c)"))
def __init__(self): super(Robot, self).__init__() self.setFlag(self.ItemHasNoContents) self.torsoItem = RobotTorso(self) self.headItem = RobotHead(self.torsoItem) self.upperLeftArmItem = RobotLimb(self.torsoItem) self.lowerLeftArmItem = RobotLimb(self.upperLeftArmItem) self.upperRightArmItem = RobotLimb(self.torsoItem) self.lowerRightArmItem = RobotLimb(self.upperRightArmItem) self.upperRightLegItem = RobotLimb(self.torsoItem) self.lowerRightLegItem = RobotLimb(self.upperRightLegItem) self.upperLeftLegItem = RobotLimb(self.torsoItem) self.lowerLeftLegItem = RobotLimb(self.upperLeftLegItem) settings = ( # Item Position Rotation Scale # x y start end (self.headItem, 0, -18, 20, -20, 1.1), (self.upperLeftArmItem, -15, -10, 190, 180, 0), (self.lowerLeftArmItem, 30, 0, 50, 10, 0), (self.upperRightArmItem, 15, -10, 300, 310, 0), (self.lowerRightArmItem, 30, 0, 0, -70, 0), (self.upperRightLegItem, 10, 32, 40, 120, 0), (self.lowerRightLegItem, 30, 0, 10, 50, 0), (self.upperLeftLegItem, -10, 32, 150, 80, 0), (self.lowerLeftLegItem, 30, 0, 70, 10, 0), (self.torsoItem, 0, 0, 5, -20, 0), ) animation = QParallelAnimationGroup(self) for item, pos_x, pos_y, start_rot, end_rot, scale in settings: item.setPos(pos_x, pos_y) rot_animation = QPropertyAnimation(item, b"rotation") rot_animation.setStartValue(start_rot) rot_animation.setEndValue(end_rot) rot_animation.setEasingCurve(QEasingCurve.SineCurve) rot_animation.setDuration(2000) animation.addAnimation(rot_animation) if scale > 0: scale_animation = QPropertyAnimation(item, b"scale") scale_animation.setEndValue(scale) scale_animation.setEasingCurve(QEasingCurve.SineCurve) scale_animation.setDuration(2000) animation.addAnimation(scale_animation) animation.setLoopCount(-1) animation.start()
def __init__(self, *args, **kwargs): super(QtBubbleLabel, self).__init__(*args, **kwargs) self.setWindowFlags(Qt.Window | Qt.Tool | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.X11BypassWindowManagerHint) self.setMinimumWidth(200) self.setMinimumHeight(48) self.setAttribute(Qt.WA_TranslucentBackground, True) layout = QVBoxLayout(self) layout.setContentsMargins(8, 8, 8, 16) self.label = QLabel(self) layout.addWidget(self.label) self._desktop = QApplication.instance().desktop() self.animationGroup = QParallelAnimationGroup(self)
def __init__(self, parent=None): super(myobj, self).__init__(parent) self.color = QColor(Qt.lightGray) animation = QParallelAnimationGroup(self) rot_animation = QPropertyAnimation(self, b'rotation') rot_animation.setStartValue(-200) rot_animation.setEndValue(600) rot_animation.setEasingCurve(QEasingCurve.SineCurve) rot_animation.setDuration(3000) animation.addAnimation(rot_animation) animation.setLoopCount(-1) animation.start()
def __init__(self, qTetris: 'QTetris', tetrimino: Tetris.Tetrimino, tile: Tetris.Tile): super(QTetris.QTile, self).__init__() tile.delegate = self self.color = self.colorMap[type(tetrimino)] self.qTetris = qTetris self.moveAnimation = QParallelAnimationGroup() self.dropAnimation = QPropertyAnimation(self, b'pos') self.collapseAnimation = QPropertyAnimation(self, b'pos') self.shiftAnimation = QPropertyAnimation(self, b'pos') self.collapseAnimation.finished.connect( lambda tl=tile: tile.delegate.disappeared(tl)) self.qTetris.scene.addItem(self) self.setPos(QPointF(0, 4)) self.moved(tile)