2025.2.28

今天继续机器人项目推进,准备添加一个历史记录查看页面,想要让这个界面展示所有历史保存记录,包括时间,原图、检测结果图等一系列数据和信息。

主页面代码:

    def setup_ui(self):
        self.setWindowTitle("智能分析系统")
        self.resize(1200, 800)
        self.setStyleSheet("background-color: #F0F0F0;")

        central_widget = QtWidgets.QWidget()
        self.setCentralWidget(central_widget)
        main_layout = QtWidgets.QVBoxLayout(central_widget)
        main_layout.setContentsMargins(10, 10, 10, 10)
        main_layout.setSpacing(10)

        # 顶部切换按钮
        btn_style = """
        QPushButton {
            background-color: #87CEFA;
            color: black;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            min-width: 120px;
            min-height: 35px;
            font-size: 14px;
        }
        QPushButton:disabled {
            background-color: #D3D3D3;
            color: gray;
        }
        """

        self.analysis_btn = QtWidgets.QPushButton("数据分析")
        self.status_btn = QtWidgets.QPushButton("今日情况")
        self.history_btn = QtWidgets.QPushButton("历史记录")
        self.analysis_btn.setStyleSheet(btn_style)
        self.status_btn.setStyleSheet(btn_style.replace("#87CEFA", "#D3D3D3").replace("black", "gray"))
        self.history_btn.setStyleSheet(btn_style.replace("#87CEFA", "#D3D3D3").replace("black", "gray"))

        top_layout = QtWidgets.QHBoxLayout()
        top_layout.addWidget(self.analysis_btn)
        top_layout.addWidget(self.status_btn)
        top_layout.addWidget(self.history_btn)
        top_layout.setSpacing(10)
        main_layout.addLayout(top_layout)

        # 页面堆栈
        self.stacked_pages = QtWidgets.QStackedWidget()
        main_layout.addWidget(self.stacked_pages)

        self.setup_analysis_page()
        self.setup_status_page()
        self.setup_history_page()

        self.analysis_btn.clicked.connect(self.switch_to_analysis)
        self.status_btn.clicked.connect(self.switch_to_status)
        self.history_btn.clicked.connect(self.switch_to_history)
        self.switch_to_analysis()

页面切换按钮:

    def switch_to_analysis(self):
        self.stacked_pages.setCurrentIndex(0)
        self.analysis_btn.setDisabled(True)
        self.status_btn.setDisabled(False)
        self.history_btn.setDisabled(False)
        self.analysis_btn.setStyleSheet("background-color: #87CEFA; color: black;")
        self.status_btn.setStyleSheet("background-color: #D3D3D3; color: gray;")
        self.history_btn.setStyleSheet("background-color: #D3D3D3; color: gray;")

    def switch_to_status(self):
        self.stacked_pages.setCurrentIndex(1)
        self.status_btn.setDisabled(True)
        self.analysis_btn.setDisabled(False)
        self.history_btn.setDisabled(False)
        self.status_btn.setStyleSheet("background-color: #87CEFA; color: black;")
        self.analysis_btn.setStyleSheet("background-color: #D3D3D3; color: gray;")
        self.history_btn.setStyleSheet("background-color: #D3D3D3; color: gray;")

    def switch_to_history(self):
        self.stacked_pages.setCurrentIndex(2)
        self.history_btn.setDisabled(True)
        self.analysis_btn.setDisabled(False)
        self.status_btn.setDisabled(False)
        self.history_btn.setStyleSheet("background-color: #87CEFA; color: black;")
        self.analysis_btn.setStyleSheet("background-color: #D3D3D3; color: gray;")
        self.status_btn.setStyleSheet("background-color: #D3D3D3; color: gray;")
        self.load_history_records()

 

posted @ 2025-02-28 21:52  贾贾鱼  阅读(10)  评论(0)    收藏  举报