-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainmenu.cpp
More file actions
219 lines (191 loc) · 6.78 KB
/
Copy pathmainmenu.cpp
File metadata and controls
219 lines (191 loc) · 6.78 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "mainmenu.h"
#include "ui_mainmenu.h"
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QSpacerItem>
#include <QFrame>
#include <QLabel>
#include "mainwindow.h"
#include "user.h"
#include "social.h"
#include<overall.h>
#include <login.h>
mainMenu::mainMenu(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::mainMenu)
{
ui->setupUi(this);
setWindowTitle("主菜单");
resize(900, 600);
QWidget *centralWidget = new QWidget(this);
QHBoxLayout *mainLayout = new QHBoxLayout(centralWidget);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
QFrame *leftPanel = new QFrame();
leftPanel->setStyleSheet(
"QFrame {"
" background: transparent;"
" border-right: 1px solid #dee2e6;"
"}"
);
leftPanel->setFixedWidth(400);
centralWidget->setStyleSheet(
"QWidget {"
" background-image: url(:/file/background-3.png);"
" background-position: center;"
" background-repeat: no-repeat;"
" background-attachment: fixed;"
"}"
);
QVBoxLayout *leftLayout = new QVBoxLayout(leftPanel);
leftLayout->setContentsMargins(60, 80, 60, 100);
leftLayout->setSpacing(100);
QWidget *buttonContainer = new QWidget();
buttonContainer->setStyleSheet("background: rgba(248, 249, 250, 150);"
" border: none;"
" padding: 12px 20px;"
" border-radius: 6px;"
);
QVBoxLayout *buttonLayout = new QVBoxLayout(buttonContainer);
buttonLayout->setContentsMargins(30, 20, 30, 60);
buttonLayout->setSpacing(30);
btnOpenMainWindow = new QPushButton("活动总览");
btnOpenUser = new QPushButton("用户界面");
btnOpenSocial = new QPushButton("交友");
btnWelcome=new QPushButton("WELCOME");
// 美化按钮样式(不改变名称)
QString buttonStyle =
"QPushButton {"
" border: none;"
" padding: 12px 20px;"
" border-radius: 6px;"
" font-family: '楷体', 'KaiTi', 'STKaiti';" // 设置楷体
" font-size: 30px;"
" color: white;"
" background-color: #4e73df;"
"}"
"QPushButton:hover {"
" background-color: #3a56c0;"
"}"
"QPushButton:pressed {"
" background-color: #2e44a8;"
"}";
btnOpenMainWindow->setStyleSheet(buttonStyle);
btnOpenUser->setStyleSheet(buttonStyle);//.replace("#4e73df", "#1cc88a").replace("#3a56c0", "#17a673").replace("#2e44a8", "#128f66"));
btnOpenSocial->setStyleSheet(buttonStyle);
btnWelcome->setStyleSheet(
"QPushButton {"
" font-size: 38px;"
" font-weight: bold;"
" color: #4e73df;" // 字体颜色改为白色
" font-weight: bold;"
" font-family: 'Arial', 'Helvetica', sans-serif;"
" padding: 0px 0px 0px 0px;" //
" background: transparent;" // 背景透明
" border: none;"
"}"
);
buttonLayout->addSpacing(20);
buttonLayout->addWidget(btnWelcome);
buttonLayout->addSpacing(50);
buttonLayout->addWidget(btnOpenMainWindow);
buttonLayout->addSpacing(40);
buttonLayout->addWidget(btnOpenUser);
buttonLayout->addSpacing(40);
buttonLayout->addWidget(btnOpenSocial);
buttonLayout->addStretch();
leftLayout->addStretch();
leftLayout->addWidget(buttonContainer);
leftLayout->addStretch();
QWidget *rightPanel = new QWidget();
rightPanel->setStyleSheet(
"background: transparent;"
"border-left: 15px solid #f8f9fa;"
);
QLabel *welcomeText = new QLabel("Welcome");
welcomeText->setStyleSheet(
"QLabel {"
" font-size: 42px;"
" color: white;" // 字体颜色改为白色
" font-weight: bold;"
" font-style: italic;"
" padding: 60px 40px 0 40px;" // 上边距60px,其他边距40px
" background: transparent;" // 背景透明
"}"
);
welcomeText->setAlignment(Qt::AlignCenter);
QLabel *welcomeLabel = new QLabel();
QPixmap pixmap(":/file/3.png"); // 使用资源路径或绝对文件路径
// 设置图片到QLabel
welcomeLabel->setPixmap(pixmap);
// 保持图片比例缩放
welcomeLabel->setScaledContents(true);
// 样式表可以保留用于其他样式设置,但字体相关的可以去掉
welcomeLabel->setStyleSheet(
"QLabel {"
" padding: 40px;"
"}"
);
welcomeLabel->setStyleSheet(
"QLabel {"
" font-size: 24px;"
" color: #5a5c69;"
" padding: 40px;"
" background: transparent;"
"}"
);
welcomeLabel->setAlignment(Qt::AlignCenter);
QVBoxLayout *rightLayout = new QVBoxLayout(rightPanel);
rightLayout->addWidget(welcomeLabel);
mainLayout->addWidget(leftPanel);
mainLayout->addWidget(rightPanel, 1); // 右侧占据剩余空间
centralWidget->setLayout(mainLayout);
setCentralWidget(centralWidget);
connect(btnOpenMainWindow, &QPushButton::clicked, this, &mainMenu::openMainWindow);
connect(btnOpenUser, &QPushButton::clicked, this, &mainMenu::openUser);
connect(btnOpenSocial, &QPushButton::clicked, this, &mainMenu::openSocial);
}
mainMenu::~mainMenu()
{
delete ui;
}
void mainMenu::openMainWindow()
{
if (!login::loggedin)
{login *loginPage = new login;
loginPage->exec();}
if (login::loggedin)
{
overall::activityList = new MainWindow(this);
overall::activityList->setWindowModality(Qt::ApplicationModal);
overall::activityList->setAttribute(Qt::WA_DeleteOnClose); // 关闭时自动删除???
overall::activityList->show();}
}
void mainMenu::openUser()
{
if (!login::loggedin)
{login *loginPage = new login;
loginPage->exec();}
if (login::loggedin)
{
user* page = new user(this);
page->setWindowModality(Qt::ApplicationModal);
page->setAttribute(Qt::WA_DeleteOnClose); // 关闭时自动删除???
page->show();}
// *SubWindow2 *subWindow = new SubWindow2(this);
// subWindow->setAttribute(Qt::WA_DeleteOnClose);
// subWindow->show();
}
void mainMenu::openSocial()
{
if (!login::loggedin)
{login *loginPage = new login;
loginPage->exec();}
if (login::loggedin)
{
Social* page = new Social(this);
page->setWindowModality(Qt::ApplicationModal);
page->setAttribute(Qt::WA_DeleteOnClose); // 关闭时自动删除???
page->show();}
}