|
| 1 | +import sys |
| 2 | + |
| 3 | +from PySide6.QtWidgets import ( |
| 4 | + QApplication, |
| 5 | + QHBoxLayout, |
| 6 | + QMainWindow, |
| 7 | + QPushButton, |
| 8 | + QStackedLayout, |
| 9 | + QVBoxLayout, |
| 10 | + QWidget, |
| 11 | +) |
| 12 | + |
| 13 | +from layout_colorwidget import Color |
| 14 | + |
| 15 | + |
| 16 | +class MainWindow(QMainWindow): |
| 17 | + def __init__(self): |
| 18 | + super().__init__() |
| 19 | + self.setWindowTitle("My App") |
| 20 | + |
| 21 | + pagelayout = QVBoxLayout() |
| 22 | + button_layout = QHBoxLayout() |
| 23 | + self.stacklayout = QStackedLayout() |
| 24 | + |
| 25 | + pagelayout.addLayout(button_layout) |
| 26 | + pagelayout.addLayout(self.stacklayout) |
| 27 | + |
| 28 | + btn = QPushButton("red") |
| 29 | + btn.pressed.connect(self.activate_tab_1) |
| 30 | + button_layout.addWidget(btn) |
| 31 | + self.stacklayout.addWidget(Color("red")) |
| 32 | + |
| 33 | + btn = QPushButton("green") |
| 34 | + btn.pressed.connect(self.activate_tab_2) |
| 35 | + button_layout.addWidget(btn) |
| 36 | + self.stacklayout.addWidget(Color("green")) |
| 37 | + |
| 38 | + btn = QPushButton("yellow") |
| 39 | + btn.pressed.connect(self.activate_tab_3) |
| 40 | + button_layout.addWidget(btn) |
| 41 | + self.stacklayout.addWidget(Color("yellow")) |
| 42 | + |
| 43 | + widget = QWidget() |
| 44 | + widget.setLayout(pagelayout) |
| 45 | + self.setCentralWidget(widget) |
| 46 | + |
| 47 | + def activate_tab_1(self): |
| 48 | + self.stacklayout.setCurrentIndex(0) |
| 49 | + |
| 50 | + def activate_tab_2(self): |
| 51 | + self.stacklayout.setCurrentIndex(1) |
| 52 | + |
| 53 | + def activate_tab_3(self): |
| 54 | + self.stacklayout.setCurrentIndex(2) |
| 55 | + |
| 56 | + |
| 57 | +app = QApplication(sys.argv) |
| 58 | +window = MainWindow() |
| 59 | +window.show() |
| 60 | +app.exec() |
0 commit comments