Day3 教学示例:增强版计算器接入 + QMainWindow/QSS 两版参考实现
- calculator_designer_ext(Day2 增强版:表达式求值 + 括号,递归下降解析器)接入 cmake - calculator_mainwindow(Day3 上午):增强版计算器装进 QMainWindow, 菜单/状态栏/历史停靠窗,纯代码 + 显式 connect,与 mainwindow_showcase 形成坑卡对照 - calculator_mainwindow_qss(Day3 下午):上午版 + QSS 双主题美化(按键分色/伪状态/深浅切换) - 验证 mainwindow_showcase(QMainWindow 六大组件综合演示,.ui + .qrc) - OUTLINE_4DAY.md / ASSIGNMENTS.md Day3 衔接增强版起点 + 参考实现指引 - 补提交 Day2 calculator/ 与 calculator_designer/ 参考实现(CMakeLists 已引用) - 全量构建 28/28,4 目标离屏自测退出码 0 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// ============================================================================
|
||||
// mainwindow_showcase.h —— MainWindow 类声明
|
||||
//
|
||||
// 主窗体的静态结构(central QTextEdit / menuBar / mainToolBar / statusBar /
|
||||
// dockWidget / 全部 QAction)在 mainwindow.ui 中用 Qt Designer 设计;
|
||||
// 本类只负责动态行为:信号槽、运行时操控、状态栏更新、关于对话框。
|
||||
//
|
||||
// 槽命名遵循 Qt 自动连接约定 on_<objectName>_<signal>,由 setupUi() 触发的
|
||||
// QMetaObject::connectSlotsByName 自动连接,无需手写 connect(KISS)。
|
||||
// ============================================================================
|
||||
#ifndef MAINWINDOW_SHOWCASE_H
|
||||
#define MAINWINDOW_SHOWCASE_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QLabel>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
private slots:
|
||||
// 文件菜单
|
||||
void on_actionNew_triggered();
|
||||
void on_actionQuit_triggered();
|
||||
|
||||
// 视图菜单 —— 操控各组件
|
||||
void on_actionToggleToolBar_toggled(bool checked); // 5.2 显示/隐藏工具栏
|
||||
void on_actionToggleStatusBar_toggled(bool checked); // 5.3 显示/隐藏状态栏
|
||||
void on_actionToggleToolBarMovable_toggled(bool checked); // 5.2 工具栏可移动
|
||||
void on_actionToggleDockFloating_triggered(); // 5.4 浮动/停靠切换
|
||||
void on_actionShowDock_triggered(); // 5.4 重新显示浮动窗口
|
||||
void on_actionHideDock_triggered(); // 5.4 关闭浮动窗口
|
||||
void on_actionToolBarAreaLeft_triggered(); // 5.2 setAllowedAreas
|
||||
void on_actionToolBarAreaRight_triggered();
|
||||
void on_actionToolBarAreaTop_triggered();
|
||||
void on_actionToolBarAreaBottom_triggered();
|
||||
void on_actionToolBarAreaAll_triggered();
|
||||
|
||||
// 帮助菜单
|
||||
void on_actionAbout_triggered();
|
||||
|
||||
// 状态栏:根据中心编辑区更新「行:列 字数:N」
|
||||
void updateStatusBar();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QLabel *statusPosLabel; // 状态栏永久标签(演示 5.3 addPermanentWidget)
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_SHOWCASE_H
|
||||
Reference in New Issue
Block a user