PyQt/QPropertyAnimation/PageSwitching.py

84 lines
2.6 KiB
Python
Raw Normal View History

2018-11-24 17:16:45 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年11月24日
author: Irony
site: https://pyqt5.com , https://github.com/892768447
email: 892768447@qq.com
2018-12-27 22:58:12 +08:00
file: PageSwitching
2018-11-24 17:16:45 +08:00
description:
"""
import os
from PyQt5.QtCore import QEasingCurve, Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel
2018-12-27 22:58:12 +08:00
from Lib.UiImageSlider import Ui_Form # @UnresolvedImport
2018-11-24 17:16:45 +08:00
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = 'Copyright (c) 2018 Irony'
__Version__ = 1.0
class ImageSliderWidget(QWidget, Ui_Form):
def __init__(self, *args, **kwargs):
super(ImageSliderWidget, self).__init__(*args, **kwargs)
self.setupUi(self)
# 初始化动画曲线类型
curve_types = [(n, c) for n, c in QEasingCurve.__dict__.items()
if isinstance(c, QEasingCurve.Type)]
curve_types.sort(key=lambda ct: ct[1])
curve_types = [c[0] for c in curve_types]
self.comboBoxEasing.addItems(curve_types)
# 绑定信号槽
self.spinBoxSpeed.valueChanged.connect(self.stackedWidget.setSpeed)
self.comboBoxEasing.currentTextChanged.connect(self.setEasing)
self.radioButtonHor.toggled.connect(self.setOrientation)
self.radioButtonVer.toggled.connect(self.setOrientation)
self.pushButtonPrev.clicked.connect(self.stackedWidget.slideInPrev)
self.pushButtonNext.clicked.connect(self.stackedWidget.slideInNext)
self.pushButtonStart.clicked.connect(self.autoStart)
self.pushButtonStop.clicked.connect(self.autoStop)
# 添加图片页面
2018-12-27 22:58:12 +08:00
for name in os.listdir('Data/Images'):
2018-11-24 17:16:45 +08:00
label = QLabel(self.stackedWidget)
label.setScaledContents(True)
2018-12-27 22:58:12 +08:00
label.setPixmap(QPixmap('Data/Images/' + name))
2018-11-24 17:16:45 +08:00
self.stackedWidget.addWidget(label)
def autoStart(self):
self.pushButtonNext.setEnabled(False)
self.pushButtonPrev.setEnabled(False)
self.stackedWidget.autoStart()
def autoStop(self):
self.pushButtonNext.setEnabled(True)
self.pushButtonPrev.setEnabled(True)
self.stackedWidget.autoStop()
def setEasing(self, name):
self.stackedWidget.setEasing(getattr(QEasingCurve, name))
def setOrientation(self, checked):
hor = self.sender() == self.radioButtonHor
if checked:
self.stackedWidget.setOrientation(
Qt.Horizontal if hor else Qt.Vertical)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = ImageSliderWidget()
w.show()
sys.exit(app.exec_())