Created
September 1, 2023 11:45
-
-
Save qycyfjy/e91cb6d1c7fbe07ea87ab5789e633938 to your computer and use it in GitHub Desktop.
PySide6 EasingCurvesDemonstration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional | |
from PySide6.QtCore import ( | |
Qt, | |
Signal, | |
QPropertyAnimation, | |
QEasingCurve, | |
QRectF, | |
Property, | |
) | |
from PySide6.QtGui import QMouseEvent, QWheelEvent, QPaintEvent, QPainter, QColor, QFont | |
from PySide6.QtWidgets import ( | |
QWidget, | |
QPushButton, | |
QHBoxLayout, | |
QDoubleSpinBox, | |
QProgressBar, | |
QComboBox, | |
QVBoxLayout, | |
) | |
class EasingDemo(QWidget): | |
def __init__(self, parent: Optional[QWidget] = None) -> None: | |
super().__init__(parent) | |
self.setWindowTitle("Easing Curve Demo") | |
self.setMinimumSize(800, 200) | |
self._easing_curves_combo_box = QComboBox() | |
curves = [curve.name for curve in QEasingCurve.Type] | |
for i, curve in enumerate(curves): | |
if i > 0x2D: | |
break | |
self._easing_curves_combo_box.addItem(curve) | |
self._easing_duration_dspin_box = QDoubleSpinBox() | |
self._easing_duration_dspin_box.setRange(300, 5000) | |
self._animate_btn = QPushButton("Start") | |
self._animate_btn.clicked.connect(self.animate) | |
self._animate_progress_bar = QProgressBar() | |
self._animate_progress_bar.setRange(0, 500) | |
layout = QHBoxLayout() | |
left_part = QVBoxLayout() | |
left_part.addWidget(self._easing_curves_combo_box) | |
left_part.addWidget(self._easing_duration_dspin_box) | |
left_part.addWidget(self._animate_btn) | |
layout.addLayout(left_part) | |
layout.addWidget(self._animate_progress_bar) | |
self.setLayout(layout) | |
self._simple_animation = QPropertyAnimation(self, b"value") | |
@Property(int) | |
def value(self): | |
return self._animate_progress_bar.value() | |
@value.setter | |
def value(self, val): | |
self._animate_progress_bar.setValue(val) | |
def animate(self): | |
self.set_easing_curve_type(self._easing_curves_combo_box.currentIndex()) | |
self._simple_animation.setDuration(self._easing_duration_dspin_box.value()) | |
self._simple_animation.setStartValue(0) | |
self._simple_animation.setEndValue(500) | |
self._simple_animation.start() | |
def set_easing_curve_type(self, value): | |
self._simple_animation.setEasingCurve(QEasingCurve.Type(value)) | |
if __name__ == "__main__": | |
from PySide6.QtWidgets import QApplication | |
app = QApplication() | |
w = EasingDemo() | |
w.show() | |
app.exec() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment