Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (45 loc) · 2.73 KB
/
Copy pathmain.cpp
File metadata and controls
58 lines (45 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "mainwindow.h"
#include <QApplication>
// 版本号由 CMakeLists 的 project(... VERSION) 注入(APP_VERSION)。
// 这里给个兜底值,方便脱离 CMake 单独编译某个文件时也不至于报错。
#ifndef APP_VERSION
#define APP_VERSION "0.0.0-dev"
#endif
// 全局样式表(QSS,语法类似 CSS):统一美化默认控件,
// 让界面呈现扁平、现代的观感。深色区域专门用于接收区,便于阅读日志。
static const char *kAppStyleSheet = R"(
QMainWindow { background-color: #f5f6f8; }
QWidget#centralwidget { background-color: #f5f6f8; }
QLabel { color: #333333; }
QComboBox, QLineEdit { background: #ffffff; color: #333333;
border: 1px solid #d0d4da;
border-radius: 6px; padding: 4px 8px; min-height: 22px; }
QComboBox:hover, QLineEdit:hover { border-color: #2d8cf0; }
/* 下拉弹出列表:只设置「视图级」配色即可(普通/选中两项都要给全)。
切记不要再写 ::item 子控件规则——那会接管列表项绘制,
反而把选中/悬浮项的配色盖掉,出现「悬浮项没有文字」的怪现象。 */
QComboBox QAbstractItemView { background: #ffffff; color: #333333; outline: 0;
border: 1px solid #d0d4da;
selection-background-color: #2d8cf0;
selection-color: #ffffff; }
QPlainTextEdit { background: #1e2127; color: #e6e6e6;
border: 1px solid #d0d4da; border-radius: 6px;
font-family: "Consolas", "DejaVu Sans Mono", monospace;
font-size: 12px; padding: 6px; }
QPushButton { background: #2d8cf0; color: #ffffff; border: none;
border-radius: 6px; padding: 6px 16px; min-height: 22px; }
QPushButton:hover { background: #4ba0f5; }
QPushButton:pressed { background: #1c72d0; }
QPushButton:disabled { background: #c2c8d0; }
QCheckBox { color: #333333; spacing: 6px; }
)";
int main(int argc, char *argv[]) {
QApplication app(argc, argv); // 每个 Qt GUI 程序有且只有一个 QApplication
// 程序名与版本号:版本号全局只在这里的 APP_VERSION(源头是 CMakeLists)定义一次
QCoreApplication::setApplicationName(QStringLiteral("Serial-Assistant"));
QCoreApplication::setApplicationVersion(QStringLiteral(APP_VERSION));
app.setStyleSheet(kAppStyleSheet);
MainWindow window; // 创建主窗口
window.show(); // 显示窗口
return QApplication::exec(); // 进入事件循环,直到窗口关闭
}