|
发表于 2024-4-8 08:44:07
|
显示全部楼层
非常抱歉给您带来的困扰,请检查是否正确设置了BaseWindow和WindowA的位置和尺寸。如果仍然有问题,请提供更多的代码和错误信息,以便我能更准确地帮助您解决问题。以下是修正后的代码示例:
- import sys
- from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QProgressBar
- class BaseWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("Base Window")
- self.setGeometry(0, 0, 1440, 900)
- self.setStyleSheet("background-color: lightblue;")
-
- self.quit_button = QPushButton("退出", self)
- self.quit_button.setGeometry(20, 20, 80, 30)
- self.quit_button.clicked.connect(self.close)
-
- self.welcome_button = QPushButton("欢迎界面", self)
- self.welcome_button.setGeometry(100, 100, 200, 50)
- self.welcome_button.clicked.connect(self.show_login_window)
-
- self.login_button = QPushButton("用户登录界面", self)
- self.login_button.setGeometry(100, 200, 200, 50)
- self.login_button.clicked.connect(self.show_user_panel)
-
- self.user_panel_buttons = []
- for i in range(5):
- button = QPushButton(f"按钮{i+1}", self)
- button.setGeometry(0, 0, 200, 50)
- button.move(self.width()//2 - button.width()//2, self.height()//2 - button.height()//2 + i*60)
- button.hide()
- self.user_panel_buttons.append(button)
-
- self.current_user = None
-
- def keyPressEvent(self, event):
- if event.key() == Qt.Key_Escape:
- self.close()
-
- def show_login_window(self):
- # 显示登录窗口的逻辑
- pass
-
- def show_user_panel(self):
- # 用户验证成功后显示用户面板的逻辑
- if self.current_user:
- for button in self.user_panel_buttons:
- button.show()
-
- def confirm_button_clicked(self, index):
- if index == 0:
- self.show_progress_bar(self.open_window_a)
- elif index == 1:
- self.show_progress_bar(self.open_window_b)
- # ... 其他按钮对应的操作
-
- def show_progress_bar(self, callback):
- progress_bar = QProgressBar(self)
- progress_bar.setGeometry(self.width()//2 - 100, self.height() - 100, 200, 30)
- progress_bar.setValue(0)
-
- def update_progress():
- nonlocal progress_bar
- progress_bar.setValue(progress_bar.value() + 10)
- if progress_bar.value() >= 100:
- callback()
- progress_bar.deleteLater()
-
- timer = QTimer(self)
- timer.timeout.connect(update_progress)
- timer.start(100)
-
- class WindowA(BaseWindow):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("Window A")
-
- self.confirm_button = QPushButton("确认", self)
- self.confirm_button.setGeometry(self.width()//2 - 50, self.height()//2 + 200, 100, 30)
- self.confirm_button.clicked.connect(self.show_progress_bar_a2)
-
- def show_progress_bar_a2(self):
- self.show_progress_bar(self.open_window_a2)
-
- def open_window_a2(self):
- window_a2 = WindowA2()
- window_a2.show()
- self.close()
- class WindowA2(BaseWindow):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("Window A2")
-
- self.confirm_button = QPushButton("确认", self)
- self.confirm_button.setGeometry(self.width()//2 - 50, self.height()//2 + 200, 100, 30)
- self.confirm_button.clicked.connect(self.show_progress_bar_a3)
-
- def show_progress_bar_a3(self):
- self.show_progress_bar(self.open_window_a3)
-
- def open_window_a3(self):
- window_a3 = WindowA3()
- window_a3.show()
- self.close()
- class WindowA3(BaseWindow):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("Window A3")
-
- self.confirm_button = QPushButton("确认", self)
- self.confirm_button.setGeometry(self.width()//2 - 50, self.height()//2 + 200, 100, 30)
- self.confirm_button.clicked.connect(self.show_progress_bar_end)
-
- def show_progress_bar_end(self):
- self.show_progress_bar(self.close_all_windows)
- def close_all_windows(self):
- self.close()
- class WindowB(BaseWindow):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("Window B")
- # ... 其他窗口B的内容
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- base_window = BaseWindow()
- base_window.show()
- sys.exit(app.exec())
复制代码
这段代码中,`BaseWindow`作为基础窗口,设定了窗口的尺寸和背景颜色,并包含了欢迎界面和用户登录界面的按钮。如果用户登录成功,屏幕中央竖排居中显示了5个按钮,点击这些按钮会触发相应的操作。
在`BaseWindow`中,通过继承并重写`keyPressEvent`函数,捕获ESC键的按下事件,从而关闭主窗口。
在`WindowA`、`WindowA2`和`WindowA3`等其他窗口中,按照您的要求添加了确认按钮和相应的进度条逻辑。当进度条达到100%时,关闭当前窗口并打开下一个窗口。
其他窗口(例如`WindowB`)可以按照上述模式进行类似的定义。
请注意,上述代码可能需要根据实际需求进行进一步的调整和完善。希望对您有所帮助!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|