83620c0cf5
- docs/teaching/OUTLINE.md、slides/day1-5.html、index.html:替换此前自定义的 4 天方案,严格对齐 docs/TRAINING_PLAN_2026.md「C++方向」Day1-5 课堂内容 (Day6-10 为纯项目实作,不在教案范围) - docs/teaching/examples/:官方方案书要求但仓库 p03/(wiki 抓取内容) 未覆盖的 QSS/Model-View/JSON/QThread/QPropertyAnimation/QStateMachine 六个技术点, 各补一个最小可运行示例 + README 教学文档,均已离屏验证跑通;手工维护, 不属于 gen_part3.py 生成产物 - 根 CMakeLists.txt:接入 docs/teaching/examples 构建(BUILD_QT_PART 分支内), 不改动生成器管理的 p01/p03 CMakeLists - 任务卡改为目标/验收标准/基础知识参考三段式模板,custom.css 配套新增样式 - docs/teaching/PRETEST.md:10 题 10 分钟 C++ 摸底测验,验证教案假定的受众 基础是否成立,并与 OUTLINE.md §0 的分层预案挂钩
59 lines
2.3 KiB
C++
59 lines
2.3 KiB
C++
// ============================================================================
|
|
// qt_qss_styling —— 教学补充示例(非 wiki 生成,手工维护)
|
|
// 用途:方案书「C++方向 Day2」要求的 QSS 界面美化,仓库 p03/ 原有 wiki 抓取内容
|
|
// 未覆盖这一点,故补一个最小示例。
|
|
// 配套文档:docs/teaching/examples/qss_styling/README.md
|
|
// 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh qt_qss_styling
|
|
// ============================================================================
|
|
|
|
#include <QApplication>
|
|
#include <QWidget>
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
#include <QVBoxLayout>
|
|
#include <QTimer>
|
|
|
|
class StyledPanel : public QWidget {
|
|
Q_OBJECT
|
|
public:
|
|
explicit StyledPanel(QWidget* parent = nullptr) : QWidget(parent) {
|
|
auto* title = new QLabel(QStringLiteral("QSS 样式演示"), this);
|
|
title->setObjectName("title");
|
|
|
|
auto* okBtn = new QPushButton(QStringLiteral("确定"), this);
|
|
okBtn->setObjectName("okButton");
|
|
|
|
auto* cancelBtn = new QPushButton(QStringLiteral("取消"), this);
|
|
cancelBtn->setObjectName("cancelButton");
|
|
|
|
auto* layout = new QVBoxLayout(this);
|
|
layout->addWidget(title);
|
|
layout->addWidget(okBtn);
|
|
layout->addWidget(cancelBtn);
|
|
|
|
// 整个窗口一份样式表:按 objectName 选择器精确命中控件,
|
|
// 也可以只用类型选择器(QPushButton { ... })一次性套所有按钮。
|
|
setStyleSheet(
|
|
"QWidget { background-color: #f4f6f8; }"
|
|
"QLabel#title { font-size: 18px; font-weight: bold; color: #2b6cb0; padding: 6px; }"
|
|
"QPushButton { border-radius: 6px; padding: 6px 14px; color: white; }"
|
|
"QPushButton#okButton { background-color: #2f855a; }"
|
|
"QPushButton#okButton:hover { background-color: #276749; }"
|
|
"QPushButton#cancelButton { background-color: #a0522d; }"
|
|
"QPushButton#cancelButton:pressed { background-color: #7b3f22; }"
|
|
);
|
|
}
|
|
};
|
|
|
|
int main(int argc, char* argv[]) {
|
|
QApplication app(argc, argv);
|
|
StyledPanel panel;
|
|
panel.resize(240, 160);
|
|
panel.show();
|
|
// 离屏/自动化验证:200ms 后自动退出(GUI 模式下不阻塞)
|
|
QTimer::singleShot(200, &app, &QApplication::quit);
|
|
return app.exec();
|
|
}
|
|
|
|
#include "qt_qss_styling.moc"
|