|
| 1 | +import sys |
| 2 | +import time |
| 3 | +from PySide6.QtGui import QColor |
| 4 | +from PySide6.QtWidgets import QMainWindow, QApplication |
| 5 | +from src.pyqt_loading_button import LoadingButton, AnimationType |
| 6 | + |
| 7 | + |
| 8 | +class Window(QMainWindow): |
| 9 | + |
| 10 | + def __init__(self): |
| 11 | + super().__init__(parent=None) |
| 12 | + |
| 13 | + # Window settings |
| 14 | + self.setWindowTitle('Example') |
| 15 | + self.setFixedSize(300, 165) |
| 16 | + |
| 17 | + # Button with circular animation |
| 18 | + self.button_1 = LoadingButton(self) |
| 19 | + self.button_1.setGeometry(94, 42, 110, 30) |
| 20 | + self.button_1.setText('Click me!') |
| 21 | + self.button_1.setAnimationType(AnimationType.Circle) # Animation type |
| 22 | + self.button_1.setAnimationSpeed(2000) # Time it takes until the animation is completed once (in ms) |
| 23 | + self.button_1.setAnimationColor(QColor(255, 255, 255)) # Animation color |
| 24 | + self.button_1.setAnimationWidth(15) # Width of the entire animation |
| 25 | + self.button_1.setAnimationStrokeWidth(3) # Width of the circle's brush stroke |
| 26 | + self.button_1.setAction(self.do_something) # Connect the button to a method |
| 27 | + self.button_1.setStyleSheet( |
| 28 | + 'color: white;' |
| 29 | + 'background: #23395d;' |
| 30 | + 'border: none;' |
| 31 | + 'border-radius: 5px;' |
| 32 | + ) |
| 33 | + |
| 34 | + # Button with dotted animation |
| 35 | + self.button_2 = LoadingButton(self) |
| 36 | + self.button_2.setGeometry(94, 82, 110, 30) |
| 37 | + self.button_2.setText('Click me!') |
| 38 | + self.button_2.setAnimationType(AnimationType.Dots) # Animation type |
| 39 | + self.button_2.setAnimationSpeed(800) # Time it takes until the animation is completed once (in ms) |
| 40 | + self.button_2.setAnimationColor(QColor(255, 255, 255)) # Animation color |
| 41 | + self.button_2.setAnimationWidth(20) # Width of the entire animation |
| 42 | + self.button_2.setAnimationStrokeWidth(4) # Width of each dot |
| 43 | + self.button_2.setAction(self.do_something) # Connect the button to a method |
| 44 | + self.button_2.setStyleSheet( |
| 45 | + 'color: white;' |
| 46 | + 'background: #23395d;' |
| 47 | + 'border: none;' |
| 48 | + 'border-radius: 5px;' |
| 49 | + ) |
| 50 | + |
| 51 | + def do_something(self): |
| 52 | + time.sleep(5) # Simulate long task |
| 53 | + |
| 54 | + |
| 55 | +# Run the example |
| 56 | +if __name__ == '__main__': |
| 57 | + app = QApplication(sys.argv) |
| 58 | + window = Window() |
| 59 | + window.show() |
| 60 | + app.exec() |
0 commit comments