-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (56 loc) · 1.95 KB
/
Copy pathmain.cpp
File metadata and controls
70 lines (56 loc) · 1.95 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
59
60
61
62
63
64
65
66
67
68
69
70
#include "MainWindow.h"
#include <QApplication>
#include <QPalette>
bool isDarkMode();
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
MainWindow mw;
mw.show();
QString commonStyles =
"QPushButton { "
" background-color: #2196F3; " // blue
" color: white; " // text color
" border-radius: 4px; " // Rounded corners
" font-weight: bold; "
" border: none; "
" padding: 5px 15px; "
" font-size: 13px; "
"} "
"QPushButton:hover { "
" background-color: #1E88E5; " // dark blue
"} "
"QPushButton:pressed { "
" background-color: #1565C0; " // dark blue
"} "
"QDialogButtonBox > QPushButton { "
" min-width: 50px; " // Minimum width for both buttons
"}"
"QGroupBox { "
"border: 2px solid #2196F3; "
" border-radius: 4px; "
" margin-top: 2ex; "
"} "
"QGroupBox::title { "
" subcontrol-origin: margin; "
" subcontrol-position: top center; " // Adjust title position to center if you want
" padding: 0 3px 0 3px; "
"}";
QString messageBoxStyle;
if (isDarkMode()) {
messageBoxStyle = "QMessageBox { background-color: #444444; }"; // dark gray
}
else {
messageBoxStyle = "QMessageBox { background-color: #eeeeee; }"; // light gray
}
app.setStyleSheet(commonStyles + messageBoxStyle);
return app.exec();
}
bool isDarkMode() {
QPalette palette = QApplication::palette();
QColor windowTextColor = palette.color(QPalette::WindowText);
QColor windowBackgroundColor = palette.color(QPalette::Window);
// Calculate the luminance (brightness) of the window text color
double luminance = 0.299 * windowTextColor.redF() + 0.587 * windowTextColor.greenF() + 0.114 * windowTextColor.blueF();
// Assuming dark mode if the luminance is low
return luminance > 0.5;
}