|
| 1 | +import sys |
| 2 | +from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QPushButton, QWidget |
| 3 | +from PySide6.QtCore import Qt |
| 4 | +from PySide6.QtGui import QColor |
| 5 | + |
| 6 | +from Custom_Widgets.QFlowProgressBar import QFlowProgressBar |
| 7 | + |
| 8 | + |
| 9 | +class MainWindow(QMainWindow): |
| 10 | + def __init__(self): |
| 11 | + super().__init__() |
| 12 | + |
| 13 | + self.setWindowTitle("Progress Bar Test") |
| 14 | + self.setGeometry(100, 100, 800, 600) |
| 15 | + |
| 16 | + main_layout = QVBoxLayout() |
| 17 | + |
| 18 | + # Initialize the QFlowProgressBase widget |
| 19 | + steps = ["Start: Step 1", "Step 2", "Step 3", "Final step: Step 4"] |
| 20 | + |
| 21 | + # Initialize different styles of QFlowProgressBar widgets with additional arguments |
| 22 | + self.flow_progress_bars = [] |
| 23 | + styles = [ |
| 24 | + QFlowProgressBar.Styles.Circular, |
| 25 | + QFlowProgressBar.Styles.Flat, |
| 26 | + QFlowProgressBar.Styles.Square |
| 27 | + ] |
| 28 | + |
| 29 | + for style in styles: |
| 30 | + # Customize colors for different progress bars |
| 31 | + if style == QFlowProgressBar.Styles.Circular: |
| 32 | + finished_color = QColor(0, 136, 254) # Blue |
| 33 | + unfinished_color = QColor(228, 231, 237) # Light gray |
| 34 | + elif style == QFlowProgressBar.Styles.Flat: |
| 35 | + finished_color = QColor(0, 176, 80) # Green |
| 36 | + unfinished_color = QColor(255, 192, 0) # Yellow |
| 37 | + else: |
| 38 | + finished_color = QColor(255, 0, 0) # Red |
| 39 | + unfinished_color = QColor(128, 128, 128) # Dark gray |
| 40 | + |
| 41 | + # Create progress bars with customized colors and labels |
| 42 | + progress_bar = QFlowProgressBar( |
| 43 | + steps, |
| 44 | + style, |
| 45 | + finishedBackgroundColor=finished_color, |
| 46 | + unfinishedBackgroundColor=unfinished_color, |
| 47 | + finishedNumberColor=Qt.white, # White |
| 48 | + numberFontSize=12, # Font size |
| 49 | + textFontSize=10, # Font size |
| 50 | + pointerDirection=QFlowProgressBar.Direction.Down, # Pointer direction for flat style |
| 51 | + animationDuration=1000, # Animation duration |
| 52 | + stepsClickable=True # Steps are clickable |
| 53 | + ) |
| 54 | + |
| 55 | + progress_bar.setMaximumHeight(100) |
| 56 | + progress_bar.setMinimumHeight(70) |
| 57 | + progress_bar.onStepClicked.connect(self.on_step_clicked) |
| 58 | + self.flow_progress_bars.append(progress_bar) |
| 59 | + |
| 60 | + # Add buttons to control the progress bars |
| 61 | + self.next_button = QPushButton("Next Step") |
| 62 | + self.next_button.clicked.connect(self.next_step) |
| 63 | + |
| 64 | + self.prev_button = QPushButton("Previous Step") |
| 65 | + self.prev_button.clicked.connect(self.prev_step) |
| 66 | + |
| 67 | + # Add widgets to layout |
| 68 | + for progress_bar in self.flow_progress_bars: |
| 69 | + main_layout.addWidget(progress_bar) |
| 70 | + |
| 71 | + main_layout.addWidget(self.next_button) |
| 72 | + main_layout.addWidget(self.prev_button) |
| 73 | + |
| 74 | + container = QWidget() |
| 75 | + container.setLayout(main_layout) |
| 76 | + self.setCentralWidget(container) |
| 77 | + |
| 78 | + def next_step(self): |
| 79 | + # Move to the next step for each progress bar |
| 80 | + for progress_bar in self.flow_progress_bars: |
| 81 | + progress_bar.changeCurrentStep(progress_bar.getCurrentStep() + 1) |
| 82 | + |
| 83 | + def prev_step(self): |
| 84 | + # Move to the previous step for each progress bar |
| 85 | + for progress_bar in self.flow_progress_bars: |
| 86 | + progress_bar.changeCurrentStep(progress_bar.getCurrentStep() - 1) |
| 87 | + |
| 88 | + def on_step_clicked(self, step: int): |
| 89 | + # Handle step clicked event |
| 90 | + print(f"Step {step + 1} clicked") |
| 91 | + |
| 92 | + # Set the clicked step for each progress bar |
| 93 | + for progress_bar in self.flow_progress_bars: |
| 94 | + progress_bar.changeCurrentStep(step + 1) |
| 95 | + |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + app = QApplication(sys.argv) |
| 99 | + |
| 100 | + window = MainWindow() |
| 101 | + window.show() |
| 102 | + |
| 103 | + sys.exit(app.exec()) |
0 commit comments