├── README.md
├── Setup.exe
├── asiawea.cpp
├── asiawea.h
├── asiawea.ui
├── citycode-2019-08-23.json
├── citywithtemp.cpp
├── citywithtemp.h
├── citywithtemp.ui
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── newWeather.pro
├── newWeather.pro.user
├── qt八股文.md
├── res.qrc
├── res
├── Search.png
├── WeaFor.png
├── aqi.png
├── back.png
├── background.png
├── bg.jpg
├── bg2.jpg
├── close.png
├── humidity.png
├── list.png
├── lowHumidty.png
├── pm25.png
├── search.png
├── sunrise.png
├── type
│ ├── BaoXue.png
│ ├── BaoYu.png
│ ├── BaoYuDaoDaBaoYu.png
│ ├── DaBaoYu.png
│ ├── DaBaoYuDaoTeDaBaoYu.png
│ ├── DaDaoBaoXue.png
│ ├── DaDaoBaoYu.png
│ ├── DaXue.png
│ ├── DaYu.png
│ ├── DongYu.png
│ ├── DuoYun.png
│ ├── FuChen.png
│ ├── LeiZhenYu.png
│ ├── LeiZhenYuBanYouBingBao.png
│ ├── Mai.png
│ ├── QiangShaChenBao.png
│ ├── Qing.png
│ ├── ShaChenBao.png
│ ├── TeDaBaoYu.png
│ ├── Wu.png
│ ├── XiaoDaoZhongXue.png
│ ├── XiaoDaoZhongYu.png
│ ├── XiaoXue.png
│ ├── XiaoYu.png
│ ├── Xue.png
│ ├── YangSha.png
│ ├── Yin.png
│ ├── Yu.png
│ ├── YuJiaXue.png
│ ├── ZhenXue.png
│ ├── ZhenYu.png
│ ├── ZhongDaoDaXue.png
│ ├── ZhongDaoDaYu.png
│ ├── ZhongXue.png
│ ├── ZhongYu.png
│ ├── neige.txt
│ └── undefined.png
├── wind.png
└── world2.png
├── weatherData.h
├── weatherTool.h
├── worldlistwea.cpp
├── worldlistwea.h
└── worldlistwea.ui
/README.md:
--------------------------------------------------------------------------------
1 | # qtWeatherForecast
2 | ## 个人qt项目,天气预报
3 |
4 | ## 目标:
5 | 制作一个方便快捷可用的天气预报,市面上目前的天气预报都太过臃肿,自己制作一个自己查看,更加灵活小巧可用。
6 |
7 | # 技术点:
8 | 该项目从国家气象局提供的 API 接口中获取 JSON 数据,使用 QT 提供的类来解析 JSON 数据并显示在项目上;发送 HTTP 请求,获得天气数据;自行绘制温度曲线和查看当前天气,所有天气图表都有显示;可以搜索中国所有城市天气预报;查看感冒指数、空气质量、未来6天空气、风力风向和最高最低温度;无边框窗口;重写了鼠标移动事件,窗口可跟随鼠标移动;右键菜单退出功能;实现选择城市列表功能;全球天气API窗口;选择城市后同步更新列表天气;编写自定义QListWidget列表,可以显示天气温度城市;传递参数到具体天气界面中;
9 |
10 | # Notice:
11 | 如果需要使用的话,需要自己修改waetherTool.h中的第20行位置filePath,方可对城市搜索进行正常使用;
12 |
13 | AsiaWea中的api也需要进行修改,这边是接入全球天气的api接口,需要在https://tianqiapi.com/user/register 这里进行注册,然后在代码中第108行填写id和app秘钥即可使用(用邮箱注册即可,不用验证码,每个邮箱免费20次试用机会)
14 |
15 | 230502更新:目前已支持全球主要城市的天气,还有一个列表可以进行选择,使用了QListWideget进行操作,然后可以进行五大洲的切换,具体再双击进行查看详细天气
16 |
17 | 开发环境:Ubuntu 22.02LTS,Qt版本5.12;
18 |
19 | 目前已在 Github 开源
20 |
21 | ***可直接下载Setup.exe安装使用***
22 |
23 | **界面展示效果:**
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | # 总结:
32 | 该天气预报总体制作点不难,比较适合Qt新手进行学习项目和熟悉代码,整体项目难点在于从接口中获取数据,然后得到JSON数据并切割出自己想要的数据并显现在界面上,这是一个小难点。总体来说制作成功,并且已经打包发布。
33 |
--------------------------------------------------------------------------------
/Setup.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/Setup.exe
--------------------------------------------------------------------------------
/asiawea.cpp:
--------------------------------------------------------------------------------
1 | #include "asiawea.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #include "ui_asiawea.h"
20 | #include "weatherData.h"
21 |
22 | #define INCREMENT 2 //温度每升高或降低1度,y轴坐标的增量
23 | #define POINT_RADIUS 3 //曲线秒点的大小
24 | #define TEXT_OFFSET_X 9 //温度文本相对于点的偏移
25 | #define TEXT_OFFSET_Y 7
26 |
27 | AsiaWea::AsiaWea(QWidget *parent) : QMainWindow(parent),
28 | ui(new Ui::AsiaWea)
29 | {
30 | ui->setupUi(this);
31 | //设置窗口属性
32 | setWindowFlag(Qt::FramelessWindowHint); // 设置无边框
33 | setFixedSize(width(), height()); // 设置固定窗口大小
34 |
35 | setWindowIcon(QIcon(":/res/WeaFor.png"));
36 |
37 | mExitMenu = new QMenu(this);
38 | mExitAct = new QAction();
39 | mExitAct->setText(tr("退出"));
40 | mExitAct->setIcon(QIcon(":/res/close.ico"));
41 | mExitMenu->addAction(mExitAct);
42 | //用lamba函数连接退出按钮,触发就退出该应用
43 | connect(mExitAct, &QAction::triggered, this, [=]() { qApp->exit(0); });
44 |
45 | weaTypeIcon();
46 |
47 | //网络请求
48 | mNetAccessManager = new QNetworkAccessManager(this);
49 | connect(mNetAccessManager,&QNetworkAccessManager::finished,this,&AsiaWea::onReplied);
50 | // getWeatherInfo("新加坡");
51 |
52 | //返回首页
53 | connect(ui->goBackBtn,&QPushButton::clicked,this,[=](){
54 | emit this->MainBtn();
55 | });
56 |
57 | //跳转list页面
58 | connect(ui->listBtn,&QPushButton::clicked,this,[=](){
59 | ListBtn->setGeometry(this->geometry());
60 | ListBtn->show();
61 | this->hide();
62 | });
63 |
64 | //返回页面
65 | connect(ListBtn,&WorldListWea::BackButton,this,[=]{
66 | this->setGeometry(ListBtn->geometry());
67 | this->show();
68 | ListBtn->hide();
69 | });
70 |
71 | //连接跟list页面的传参
72 | connect(ListBtn,SIGNAL(setData(QString)),this,SLOT(GetData(QString)));
73 |
74 | //给标签添加事件过滤器
75 | ui->lblHighCurve->installEventFilter(this);
76 | ui->lblLowCurve->installEventFilter(this);
77 | }
78 |
79 | AsiaWea::~AsiaWea()
80 | {
81 | delete ui;
82 | }
83 |
84 | void AsiaWea::contextMenuEvent(QContextMenuEvent *event)
85 | {
86 | //弹出右键菜单
87 | mExitMenu->exec(QCursor::pos());
88 | event->accept();
89 | }
90 |
91 | void AsiaWea::mousePressEvent(QMouseEvent *event)
92 | {
93 | mOffset = event->globalPos() - this->pos();
94 | }
95 |
96 | void AsiaWea::mouseMoveEvent(QMouseEvent *event)
97 | {
98 | this->move(event->globalPos() - mOffset);
99 | }
100 |
101 | void AsiaWea::getWeatherInfo(QString cityName)
102 | {
103 | if(errmsg != ""){
104 | qDebug() << errmsg;
105 | QMessageBox::warning(this,"提示","暂时不支持该城市",QMessageBox::Ok);
106 | return;
107 | }
108 | QUrl url("http://yiketianqi.com/api?version=v5&appid=[id]&appsecret=[appsec]&city=" + cityName);
109 | mNetAccessManager->get(QNetworkRequest(url));
110 | }
111 |
112 | void AsiaWea::parseJson(QByteArray &byteArray)
113 | {
114 | QJsonParseError err;
115 | QJsonDocument doc = QJsonDocument::fromJson(byteArray,&err);
116 | if(err.error != QJsonParseError::NoError){
117 | return;
118 | }
119 |
120 | QJsonObject rootObj = doc.object();
121 | errmsg = rootObj.value("errmsg").toString();
122 | qDebug() << "errmsg:" << errmsg;
123 | QJsonArray dataArr = rootObj.value("data").toArray();
124 | //解析日期和城市
125 | mToday.date = dataArr[0].toObject().value("date").toString();
126 | mToday.city = rootObj.value("city").toString();
127 |
128 | //解析日期\风向\风力\温度
129 | for(int i = 0;i < 6;i++){
130 | QJsonObject objDate = dataArr[i].toObject();
131 | QJsonArray objWin = objDate.value("win").toArray();
132 |
133 | mDay[i].date = objDate.value("date").toString();
134 | mDay[i].high = objDate.value("tem1").toString().toInt();
135 | mDay[i].low = objDate.value("tem2").toString().toInt();
136 | //天气类型
137 | mDay[i].type = objDate.value("wea").toString();
138 | mDay[i].week = objDate.value("wea_img").toString();
139 |
140 | mDay[i].fx = objWin[0].toString();
141 | mDay[i].fl = objDate.value("win_speed").toString().right(2);
142 | }
143 |
144 | mToday.wendu = (mDay[0].high + mDay[0].low) / 2;
145 | mToday.type = dataArr[0].toObject().value("wea").toString();
146 |
147 | mToday.fx = mDay[0].fx;
148 | mToday.fl = mDay[0].fl;
149 |
150 | mToday.high = mDay[0].high;
151 | mToday.low = mDay[0].low;
152 | //更新UI
153 | updateUI();
154 |
155 | //绘制最高最低温度曲线
156 | ui->lblHighCurve->update();
157 | ui->lblLowCurve->update();
158 | }
159 |
160 | void AsiaWea::updateUI()
161 | {
162 | //更新日期和城市
163 | ui->lblDate->setText(QDateTime::fromString(mToday.date,"yyyy-MM-dd").toString("yyyy/MM/dd"));
164 | ui->lblCity->setText(mToday.city);
165 |
166 | ui->lblTypeIcon->setPixmap(mTypeMap[mDay[0].week]);
167 | ui->lblTemp->setText(QString::number(mToday.wendu) +"°");
168 | ui->lblLowHigh->setText(QString::number(mToday.low) + "~"
169 | + QString::number(mToday.high) + "°C");
170 | ui->lblType->setText(mToday.type);
171 |
172 | ui->lblWindFx->setText(mToday.fx);
173 | ui->lblWindFl->setText(mToday.fl);
174 |
175 | if(errmsg != ""){
176 | qDebug() << "该城市不存在或出错";
177 | return;
178 | }
179 |
180 | //更新六天的数据
181 | for(int i = 0;i < 6;i++){
182 | QStringList ymdList = mDay[i].date.split("-");
183 | mDateList[i]->setText(ymdList[1] + "/" + ymdList[2]);
184 |
185 | //更新天气类型
186 | mTypeList[i]->setText(mDay[i].type);
187 | mTypeIconList[i]->setPixmap(mTypeMap[mDay[i].week]);
188 | //更新风向\风力
189 | mFxList[i]->setText(mDay[i].fx);
190 | mFlList[i]->setText(mDay[i].fl);
191 | }
192 | QString city = ui->lblCity->text();
193 | QString temp = ui->lblLowHigh->text();
194 | QString type = mTypeMap[mDay[0].week];
195 | emit sendTemp(city,temp,type);
196 | }
197 |
198 | //消息过滤,主要用于重绘子控件,过滤Paint事件
199 | bool AsiaWea::eventFilter(QObject *watched, QEvent *event)
200 | {
201 | //绘制最高温度曲线
202 | if(watched == ui->lblHighCurve && event->type() == QEvent::Paint){
203 | paintHighCurve();
204 | }
205 | //绘制最低温度曲线
206 | if(watched == ui->lblLowCurve && event->type() == QEvent::Paint){
207 | paintLowCurve();
208 | }
209 | return QWidget::eventFilter(watched,event);
210 | }
211 |
212 | void AsiaWea::paintHighCurve()
213 | {
214 | QPainter painter(ui->lblHighCurve);
215 |
216 | // 抗锯齿 使图形绘制更加平滑
217 | painter.setRenderHint(QPainter::Antialiasing,true);
218 |
219 | //获取x坐标
220 | int pointX[6] = {0};
221 | for(int i = 0;i < 6;i++){
222 | pointX[i] = mWeekList[i]->pos().x() + mWeekList[i]->width() / 2;
223 | }
224 |
225 | int tmpSum = 0;
226 | int tmpAvg = 0;
227 | for(int i = 0;i < 6;i++){
228 | tmpSum += mDay[i].high;
229 | }
230 | tmpAvg = tmpSum / 6;
231 | //获取y坐标
232 | int pointY[6] = {0};
233 | int yCenter = ui->lblHighCurve->height() / 2;
234 | for(int i = 0;i < 6;i++){
235 | pointY[i] = yCenter - ((mDay[i].high - tmpAvg) * INCREMENT);
236 | }
237 | //绘制
238 | QPen pen = painter.pen();
239 | pen.setWidth(1);
240 | pen.setColor(QColor(255,170,0));
241 |
242 | painter.setPen(pen);
243 | painter.setBrush(QColor(255,170,0)); //设置画刷内部填充的颜色
244 |
245 | //画点、写文本
246 | for(int i = 0;i < 6;i++){
247 | painter.drawEllipse(QPoint(pointX[i],pointY[i]),POINT_RADIUS,POINT_RADIUS);
248 | //显示温度文本
249 | painter.drawText(pointX[i] - TEXT_OFFSET_X, pointY[i]
250 | - TEXT_OFFSET_Y,QString::number(mDay[i].high) + "°");
251 | }
252 | for(int i = 0;i < 5;i++){
253 | pen.setStyle(Qt::SolidLine);
254 | painter.setPen(pen);
255 | painter.drawLine(pointX[i],pointY[i],pointX[i + 1],pointY[i + 1]);
256 | }
257 | }
258 |
259 | void AsiaWea::paintLowCurve()
260 | {
261 | QPainter painter(ui->lblLowCurve);
262 |
263 | // 抗锯齿
264 | painter.setRenderHint(QPainter::Antialiasing,true);
265 |
266 | //获取x坐标
267 | int pointX[6] = {0};
268 | for(int i = 0;i < 6;i++){
269 | pointX[i] = mWeekList[i]->pos().x() + mWeekList[i]->width() / 2;
270 | }
271 | //获取y坐标
272 | int pointY[6] = {0};
273 | int yCenter = ui->lblLowCurve->height() / 2;
274 | //求平均气温
275 | int tmpSum = 0;
276 | int tmpAvg = 0;
277 | for(int i = 0;i < 6;i++){
278 | tmpSum += mDay[i].low;
279 | }
280 | tmpAvg = tmpSum / 6;
281 |
282 | for(int i = 0;i < 6;i++){
283 | pointY[i] = yCenter - ((mDay[i].low - tmpAvg) * INCREMENT);
284 | }
285 | //绘制
286 | QPen pen = painter.pen();
287 | pen.setWidth(1);
288 | pen.setColor(QColor(0,255,255));
289 |
290 | painter.setPen(pen);
291 | painter.setBrush(QColor(0,255,255)); //设置画刷内部填充的颜色
292 | //画点、写文本
293 | for(int i = 0;i < 6;i++){
294 | painter.drawEllipse(QPoint(pointX[i],pointY[i]),POINT_RADIUS,POINT_RADIUS);
295 | //显示温度文本
296 | painter.drawText(pointX[i] - TEXT_OFFSET_X,pointY[i] - TEXT_OFFSET_Y,QString::number(mDay[i].low) + "°");
297 | }
298 | for(int i = 0;i < 5;i++){
299 | pen.setStyle(Qt::SolidLine);
300 | painter.setPen(pen);
301 | painter.drawLine(pointX[i],pointY[i],pointX[i + 1],pointY[i + 1]);
302 | }
303 | }
304 |
305 | void AsiaWea::weaTypeIcon()
306 | {
307 | //将控件添加到控件数组
308 | mWeekList << ui->lblWeek0 << ui->lblWeek1 << ui->lblWeek2 << ui->lblWeek3 << ui->lblWeek4 << ui->lblWeek5;
309 | mDateList << ui->lblDate0 << ui->lblDate1 << ui->lblDate2 << ui->lblDate3 << ui->lblDate4 << ui->lblDate5;
310 |
311 | mTypeList << ui->lblType0 << ui->lblType1 << ui->lblType2 << ui->lblType3 << ui->lblType4 << ui->lblType5;
312 | mTypeIconList << ui->lblTypeIcon0 << ui->lblTypeIcon1 << ui->lblTypeIcon2 << ui->lblTypeIcon3 << ui->lblTypeIcon4 << ui->lblTypeIcon5;
313 |
314 | mAqiList << ui->lblQuality0 << ui->lblQuality1 << ui->lblQuality2 << ui->lblQuality3 << ui->lblQuality4 << ui->lblQuality5;
315 |
316 | mFxList << ui->lblFx0 << ui->lblFx1 << ui->lblFx2 << ui->lblFx3 << ui->lblFx4 << ui->lblFx5;
317 | mFlList << ui->lblFl0 << ui->lblFl1 << ui->lblFl2 << ui->lblFl3 << ui->lblFl4 << ui->lblFl5;
318 |
319 | mTypeMap.insert("xue",":/res/type/Xue.png");
320 | mTypeMap.insert("wu",":/res/type/Wu.png");
321 | mTypeMap.insert("lei",":/res/type/LeiZhenYu.png");
322 | mTypeMap.insert("shachen",":/res/type/ShaChenBao.png");
323 | mTypeMap.insert("bingbao",":/res/type/DaXue.png");
324 | mTypeMap.insert("qing",":/res/type/Qing.png");
325 | mTypeMap.insert("yun",":/res/type/DuoYun.png");
326 | mTypeMap.insert("yin",":/res/type/Yin.png");
327 | mTypeMap.insert("yu",":/res/type/Yu.png");
328 | }
329 |
330 | void AsiaWea::GetData(QString city)
331 | {
332 | getWeatherInfo(city);
333 | connect(this,SIGNAL(sendTemp(QString,QString,QString)),ListBtn,SLOT(getTemp(QString,QString,QString)));
334 | ListBtn->hide();
335 | this->setGeometry(ListBtn->geometry());
336 | this->show();
337 | }
338 |
339 | void AsiaWea::onReplied(QNetworkReply *reply){
340 | int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
341 | if(reply->error() != QNetworkReply::NoError || statusCode != 200){
342 | qDebug() << reply->errorString().toLatin1().data();
343 | QMessageBox::warning(this,"天气","请求数据失败",QMessageBox::Ok);
344 | }else{
345 | QByteArray byteArray = reply->readAll();
346 | // qDebug() << "Asia读所有:" << byteArray.data();
347 | parseJson(byteArray);
348 | }
349 | reply->deleteLater();
350 | }
351 |
--------------------------------------------------------------------------------
/asiawea.h:
--------------------------------------------------------------------------------
1 | #ifndef ASIAWEA_H
2 | #define ASIAWEA_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include "weatherData.h"
8 | #include "worldlistwea.h"
9 | #include
10 | #include
11 |
12 | QT_BEGIN_NAMESPACE
13 | namespace Ui {
14 | class AsiaWea;
15 | }
16 | QT_END_NAMESPACE
17 |
18 | class AsiaWea : public QMainWindow
19 | {
20 | Q_OBJECT
21 |
22 | public:
23 | explicit AsiaWea(QWidget *parent = nullptr);
24 | ~AsiaWea();
25 | //得到返回值按钮
26 | WorldListWea* ListBtn = new WorldListWea;
27 | QString errmsg;
28 |
29 | protected:
30 | void contextMenuEvent(QContextMenuEvent* event);
31 | void mousePressEvent(QMouseEvent* event);
32 | void mouseMoveEvent(QMouseEvent* event);
33 | //获取天气数据、解析Json、更新UI
34 | void getWeatherInfo(QString cityName);
35 | void parseJson(QByteArray& byteArray);
36 | void updateUI();
37 | //重写父类的eventFilter方法
38 | bool eventFilter(QObject* watched,QEvent* event);
39 | void paintHighCurve();
40 | void paintLowCurve();
41 | void weaTypeIcon();
42 |
43 | private slots:
44 | void GetData(QString);
45 |
46 | signals:
47 | void MainBtn();
48 | void sendTemp(QString temp,QString city,QString type);
49 |
50 | private:
51 | void onReplied(QNetworkReply* reply);
52 |
53 | private:
54 | Ui::AsiaWea *ui;
55 |
56 | QMenu* mExitMenu; // 退出菜单
57 | QAction* mExitAct; // 菜单项(退出)
58 | QPoint mOffset; //窗口移动时,鼠标与左上角的偏移
59 |
60 | QNetworkAccessManager* mNetAccessManager;
61 |
62 | Today mToday;
63 | Day mDay[6];
64 | //星期和日期
65 | QList mWeekList;
66 | QList mDateList;
67 |
68 | //天气和图标
69 | QList mTypeList;
70 | QList mTypeIconList;
71 |
72 | // 质量指数
73 | QList mAqiList;
74 |
75 | //风力风向
76 | QList mFxList;
77 | QList mFlList;
78 |
79 | QMapmTypeMap;
80 | };
81 | #endif // ASIAWEA_H
82 |
--------------------------------------------------------------------------------
/asiawea.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | AsiaWea
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 450
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 0
21 | 0
22 | 800
23 | 500
24 |
25 |
26 |
27 | QWidget#widget{
28 | border-image: url(:/res/bg.jpg);
29 | }
30 |
31 | QLabel {
32 | font: 25 10pt "微软雅黑";
33 | border-radius: 4px;
34 | background-color: rgba(60, 60, 60, 100);
35 | color: rgb(255, 255, 255);
36 | }
37 |
38 |
39 |
40 |
41 | 10
42 | 70
43 | 341
44 | 121
45 |
46 |
47 |
48 | background-color: rgba(157, 133, 255, 0);
49 | border-radius: 15px
50 |
51 |
52 |
53 | 8
54 |
55 | -
56 |
57 |
58 |
59 | 110
60 | 110
61 |
62 |
63 |
64 |
65 | 110
66 | 110
67 |
68 |
69 |
70 | background-color: rgba(255, 255, 255, 0);
71 |
72 |
73 |
74 |
75 |
76 | :/res/type/DuoYun.png
77 |
78 |
79 | true
80 |
81 |
82 | Qt::AlignCenter
83 |
84 |
85 |
86 | -
87 |
88 |
89 | 0
90 |
91 |
-
92 |
93 |
-
94 |
95 |
96 |
97 | Arial
98 | 50
99 | 50
100 | false
101 | false
102 |
103 |
104 |
105 | color: rgb(255, 255, 255);
106 | font: 50pt "Arial";
107 | background-color: rgba(0, 255, 255, 0);
108 |
109 |
110 | 13°
111 |
112 |
113 | true
114 |
115 |
116 | Qt::AlignCenter
117 |
118 |
119 |
120 | -
121 |
122 |
123 | Qt::Horizontal
124 |
125 |
126 |
127 | 40
128 | 20
129 |
130 |
131 |
132 |
133 | -
134 |
135 |
136 | 0
137 |
138 |
139 | 40
140 |
141 |
-
142 |
143 |
144 | font: 12pt "Microsoft YaHei UI";
145 | background-color: rgba(255, 255, 255,0);
146 |
147 |
148 | 北京
149 |
150 |
151 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | -
160 |
161 |
162 | 6
163 |
164 |
165 | QLayout::SetDefaultConstraint
166 |
167 |
-
168 |
169 |
170 |
171 | 0
172 | 0
173 |
174 |
175 |
176 | background-color: rgba(255, 255, 255,0);
177 | font: 12pt "微软雅黑";
178 |
179 |
180 | 晴转多云
181 |
182 |
183 | true
184 |
185 |
186 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
187 |
188 |
189 |
190 | -
191 |
192 |
193 |
194 | 0
195 | 15
196 |
197 |
198 |
199 |
200 | 16777215
201 | 15
202 |
203 |
204 |
205 | color: rgb(255, 0, 0);
206 |
207 |
208 | Qt::Vertical
209 |
210 |
211 |
212 | -
213 |
214 |
215 | background-color: rgba(255, 255, 255,0);
216 | font: 12pt "微软雅黑";
217 |
218 |
219 | 9°~15°
220 |
221 |
222 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
223 |
224 |
225 |
226 | -
227 |
228 |
229 | Qt::Horizontal
230 |
231 |
232 |
233 | 40
234 | 20
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 | 0
249 | 0
250 | 801
251 | 49
252 |
253 |
254 |
255 | background-color: rgba(0, 170, 255,0);
256 |
257 |
258 |
259 | 15
260 |
261 |
262 | 20
263 |
264 | -
265 |
266 |
267 | background-color: rgba(0, 0, 0,1);
268 |
269 |
270 |
271 |
272 |
273 |
274 | :/res/back.png:/res/back.png
275 |
276 |
277 |
278 | -
279 |
280 |
281 | background-color: rgba(0, 0, 0,1);
282 |
283 |
284 |
285 |
286 |
287 |
288 | :/res/list.png:/res/list.png
289 |
290 |
291 |
292 | -
293 |
294 |
295 | Qt::Horizontal
296 |
297 |
298 |
299 | 309
300 | 20
301 |
302 |
303 |
304 |
305 | -
306 |
307 |
308 | font: 20pt "Arial";
309 | background-color: rgba(255, 255, 255,0);
310 |
311 |
312 | 2023/05/13 星期四
313 |
314 |
315 | Qt::AlignCenter
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 | 10
325 | 190
326 | 341
327 | 241
328 |
329 |
330 |
331 | -
332 |
333 |
334 | Qt::Vertical
335 |
336 |
337 |
338 | 20
339 | 10
340 |
341 |
342 |
343 |
344 | -
345 |
346 |
347 | background-color: rgba(60, 60, 60, 0);
348 | padding-left: 5px;
349 | padding-right: 5px;
350 |
351 |
352 | 感冒指数:各类人群可自由活动
353 |
354 |
355 | true
356 |
357 |
358 |
359 | -
360 |
361 |
362 | background-color: rgb(255, 182, 193);
363 | border-radius: 15px
364 |
365 |
366 |
367 | 40
368 |
369 |
370 | 25
371 |
372 |
373 | 40
374 |
375 |
376 | 25
377 |
378 |
379 | 50
380 |
381 |
382 | 20
383 |
384 |
-
385 |
386 |
387 | 0
388 |
389 |
-
390 |
391 |
392 |
393 | 40
394 | 40
395 |
396 |
397 |
398 |
399 | 40
400 | 40
401 |
402 |
403 |
404 | background-color: rgba(255, 255, 255, 0);
405 |
406 |
407 |
408 |
409 |
410 | :/res/wind.png
411 |
412 |
413 | true
414 |
415 |
416 | Qt::AlignCenter
417 |
418 |
419 |
420 | -
421 |
422 |
-
423 |
424 |
425 | background-color: rgba(255, 255, 255,0);
426 | font: 10pt "微软雅黑";
427 |
428 |
429 | 西北风
430 |
431 |
432 | Qt::AlignCenter
433 |
434 |
435 |
436 | -
437 |
438 |
439 | background-color: rgba(255, 255, 255,0);
440 | font: 10pt "微软雅黑";
441 |
442 |
443 | 3级
444 |
445 |
446 | Qt::AlignCenter
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 | -
455 |
456 |
457 | 0
458 |
459 |
-
460 |
461 |
462 |
463 | 40
464 | 40
465 |
466 |
467 |
468 |
469 | 40
470 | 40
471 |
472 |
473 |
474 | background-color: rgba(255, 255, 255, 0);
475 |
476 |
477 |
478 |
479 |
480 | :/res/pm25.png
481 |
482 |
483 | true
484 |
485 |
486 | Qt::AlignCenter
487 |
488 |
489 |
490 | -
491 |
492 |
-
493 |
494 |
495 | background-color: rgba(255, 255, 255,0);
496 | font: 10pt "微软雅黑";
497 |
498 |
499 | PM2.5
500 |
501 |
502 | Qt::AlignCenter
503 |
504 |
505 |
506 | -
507 |
508 |
509 | background-color: rgba(255, 255, 255,0);
510 | font: 10pt "微软雅黑";
511 |
512 |
513 | 8
514 |
515 |
516 | Qt::AlignCenter
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 | -
525 |
526 |
527 | 0
528 |
529 |
-
530 |
531 |
532 |
533 | 40
534 | 40
535 |
536 |
537 |
538 |
539 | 40
540 | 40
541 |
542 |
543 |
544 | background-color: rgba(255, 255, 255, 0);
545 |
546 |
547 |
548 |
549 |
550 | :/res/humidity.png
551 |
552 |
553 | true
554 |
555 |
556 | Qt::AlignCenter
557 |
558 |
559 |
560 | -
561 |
562 |
-
563 |
564 |
565 | background-color: rgba(255, 255, 255,0);
566 | font: 10pt "微软雅黑";
567 |
568 |
569 | 湿度
570 |
571 |
572 | Qt::AlignCenter
573 |
574 |
575 |
576 | -
577 |
578 |
579 | background-color: rgba(255, 255, 255,0);
580 | font: 10pt "微软雅黑";
581 |
582 |
583 | 72%
584 |
585 |
586 | Qt::AlignCenter
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 | -
595 |
596 |
597 | 0
598 |
599 |
-
600 |
601 |
602 |
603 | 40
604 | 40
605 |
606 |
607 |
608 |
609 | 40
610 | 40
611 |
612 |
613 |
614 | false
615 |
616 |
617 | background-color: rgba(255, 255, 255, 0);
618 |
619 |
620 |
621 |
622 |
623 | :/res/aqi.png
624 |
625 |
626 | true
627 |
628 |
629 | Qt::AlignCenter
630 |
631 |
632 | false
633 |
634 |
635 | -1
636 |
637 |
638 |
639 | -
640 |
641 |
-
642 |
643 |
644 | false
645 |
646 |
647 | background-color: rgba(255, 255, 255,0);
648 | font: 10pt "微软雅黑";
649 |
650 |
651 | 空气质量
652 |
653 |
654 | Qt::AlignCenter
655 |
656 |
657 |
658 | -
659 |
660 |
661 | false
662 |
663 |
664 | background-color: rgba(255, 255, 255,0);
665 | font: 10pt "微软雅黑";
666 |
667 |
668 | 优
669 |
670 |
671 | Qt::AlignCenter
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 | 360
688 | 40
689 | 451
690 | 411
691 |
692 |
693 |
694 |
695 | 0
696 |
697 | -
698 |
699 |
700 | QLabel {
701 | background-color: rgba(0, 200, 200, 200);
702 | border-radius: 4px;
703 | }
704 |
705 |
706 |
707 | 6
708 |
709 |
710 | 0
711 |
712 |
-
713 |
714 |
715 | border-bottom-left-radius: 0px;
716 | border-bottom-right-radius: 0px;
717 |
718 |
719 | 今天
720 |
721 |
722 | Qt::AlignCenter
723 |
724 |
725 |
726 | -
727 |
728 |
729 | border-bottom-left-radius: 0px;
730 | border-bottom-right-radius: 0px;
731 |
732 |
733 | 明天
734 |
735 |
736 | Qt::AlignCenter
737 |
738 |
739 |
740 | -
741 |
742 |
743 | border-bottom-left-radius: 0px;
744 | border-bottom-right-radius: 0px;
745 |
746 |
747 | 后天
748 |
749 |
750 | Qt::AlignCenter
751 |
752 |
753 |
754 | -
755 |
756 |
757 | border-bottom-left-radius: 0px;
758 | border-bottom-right-radius: 0px;
759 |
760 |
761 | 周四
762 |
763 |
764 | Qt::AlignCenter
765 |
766 |
767 |
768 | -
769 |
770 |
771 | border-bottom-left-radius: 0px;
772 | border-bottom-right-radius: 0px;
773 |
774 |
775 | 周五
776 |
777 |
778 | Qt::AlignCenter
779 |
780 |
781 |
782 | -
783 |
784 |
785 | border-bottom-left-radius: 0px;
786 | border-bottom-right-radius: 0px;
787 |
788 |
789 | 周六
790 |
791 |
792 | Qt::AlignCenter
793 |
794 |
795 |
796 | -
797 |
798 |
799 | border-top-left-radius: 0px;
800 | border-top-right-radius: 0px;
801 | color: rgb(240, 240, 240);
802 |
803 |
804 | 01/01
805 |
806 |
807 | Qt::AlignCenter
808 |
809 |
810 |
811 | -
812 |
813 |
814 | border-top-left-radius: 0px;
815 | border-top-right-radius: 0px;
816 | color: rgb(240, 240, 240);
817 |
818 |
819 | 01/02
820 |
821 |
822 | Qt::AlignCenter
823 |
824 |
825 |
826 | -
827 |
828 |
829 | border-top-left-radius: 0px;
830 | border-top-right-radius: 0px;
831 | color: rgb(240, 240, 240);
832 |
833 |
834 | 01/03
835 |
836 |
837 | Qt::AlignCenter
838 |
839 |
840 |
841 | -
842 |
843 |
844 | border-top-left-radius: 0px;
845 | border-top-right-radius: 0px;
846 | color: rgb(240, 240, 240);
847 |
848 |
849 | 01/04
850 |
851 |
852 | Qt::AlignCenter
853 |
854 |
855 |
856 | -
857 |
858 |
859 | border-top-left-radius: 0px;
860 | border-top-right-radius: 0px;
861 | color: rgb(240, 240, 240);
862 |
863 |
864 | 01/05
865 |
866 |
867 | Qt::AlignCenter
868 |
869 |
870 |
871 | -
872 |
873 |
874 | border-top-left-radius: 0px;
875 | border-top-right-radius: 0px;
876 | color: rgb(240, 240, 240);
877 |
878 |
879 | 01/06
880 |
881 |
882 | Qt::AlignCenter
883 |
884 |
885 |
886 |
887 |
888 |
889 | -
890 |
891 |
892 | QLabel {
893 | background-color: rgba(60, 60, 60, 100);
894 | border-radius: 4px;
895 | }
896 |
897 |
898 |
899 | 5
900 |
901 |
902 | 5
903 |
904 |
905 | 0
906 |
907 |
-
908 |
909 |
910 | border-bottom-left-radius: 0px;
911 | border-bottom-right-radius: 0px;
912 |
913 |
914 |
915 |
916 |
917 | :/res/type/DuoYun.png
918 |
919 |
920 | Qt::AlignCenter
921 |
922 |
923 |
924 | -
925 |
926 |
927 |
928 | 0
929 | 0
930 |
931 |
932 |
933 |
934 | 1000
935 | 1000
936 |
937 |
938 |
939 | border-bottom-left-radius: 0px;
940 | border-bottom-right-radius: 0px;
941 |
942 |
943 |
944 |
945 |
946 | :/res/type/Qing.png
947 |
948 |
949 | Qt::AlignCenter
950 |
951 |
952 |
953 | -
954 |
955 |
956 | border-bottom-left-radius: 0px;
957 | border-bottom-right-radius: 0px;
958 |
959 |
960 |
961 |
962 |
963 | :/res/type/DuoYun.png
964 |
965 |
966 | Qt::AlignCenter
967 |
968 |
969 |
970 | -
971 |
972 |
973 | border-top-left-radius: 0px;
974 | border-top-right-radius: 0px;
975 |
976 |
977 | 晴
978 |
979 |
980 | Qt::AlignCenter
981 |
982 |
983 |
984 | -
985 |
986 |
987 | border-top-left-radius: 0px;
988 | border-top-right-radius: 0px;
989 |
990 |
991 | 多云
992 |
993 |
994 | Qt::AlignCenter
995 |
996 |
997 |
998 | -
999 |
1000 |
1001 | border-bottom-left-radius: 0px;
1002 | border-bottom-right-radius: 0px;
1003 |
1004 |
1005 |
1006 |
1007 |
1008 | :/res/type/BaoYu.png
1009 |
1010 |
1011 | Qt::AlignCenter
1012 |
1013 |
1014 |
1015 | -
1016 |
1017 |
1018 | border-top-left-radius: 0px;
1019 | border-top-right-radius: 0px;
1020 |
1021 |
1022 | 暴雨
1023 |
1024 |
1025 | Qt::AlignCenter
1026 |
1027 |
1028 |
1029 | -
1030 |
1031 |
1032 | border-top-left-radius: 0px;
1033 | border-top-right-radius: 0px;
1034 |
1035 |
1036 | 中雨
1037 |
1038 |
1039 | Qt::AlignCenter
1040 |
1041 |
1042 |
1043 | -
1044 |
1045 |
1046 | border-bottom-left-radius: 0px;
1047 | border-bottom-right-radius: 0px;
1048 |
1049 |
1050 |
1051 |
1052 |
1053 | :/res/type/XiaoYu.png
1054 |
1055 |
1056 | Qt::AlignCenter
1057 |
1058 |
1059 |
1060 | -
1061 |
1062 |
1063 | border-top-left-radius: 0px;
1064 | border-top-right-radius: 0px;
1065 |
1066 |
1067 | 多云
1068 |
1069 |
1070 | Qt::AlignCenter
1071 |
1072 |
1073 |
1074 | -
1075 |
1076 |
1077 | border-bottom-left-radius: 0px;
1078 | border-bottom-right-radius: 0px;
1079 |
1080 |
1081 |
1082 |
1083 |
1084 | :/res/type/ZhongYu.png
1085 |
1086 |
1087 | Qt::AlignCenter
1088 |
1089 |
1090 |
1091 | -
1092 |
1093 |
1094 | border-top-left-radius: 0px;
1095 | border-top-right-radius: 0px;
1096 |
1097 |
1098 | 小雨
1099 |
1100 |
1101 | Qt::AlignCenter
1102 |
1103 |
1104 |
1105 |
1106 |
1107 |
1108 | -
1109 |
1110 |
1111 |
1112 | 5
1113 |
1114 |
1115 | 5
1116 |
1117 |
-
1118 |
1119 |
1120 | background-color: rgb(121, 184, 0);
1121 | padding:8px;
1122 |
1123 |
1124 | 优
1125 |
1126 |
1127 | Qt::AlignCenter
1128 |
1129 |
1130 |
1131 | -
1132 |
1133 |
1134 | background-color: rgb(255, 187, 23);
1135 |
1136 |
1137 | 良
1138 |
1139 |
1140 | Qt::AlignCenter
1141 |
1142 |
1143 |
1144 | -
1145 |
1146 |
1147 | background-color: rgb(255, 187, 23);
1148 |
1149 |
1150 | 良
1151 |
1152 |
1153 | Qt::AlignCenter
1154 |
1155 |
1156 |
1157 | -
1158 |
1159 |
1160 | background-color: rgb(255, 187, 23);
1161 |
1162 |
1163 | 良
1164 |
1165 |
1166 | Qt::AlignCenter
1167 |
1168 |
1169 |
1170 | -
1171 |
1172 |
1173 | background-color: rgb(121, 184, 0);
1174 | padding:8px;
1175 |
1176 |
1177 | 优
1178 |
1179 |
1180 | Qt::AlignCenter
1181 |
1182 |
1183 |
1184 | -
1185 |
1186 |
1187 | background-color: rgb(121, 184, 0);
1188 | padding:8px;
1189 |
1190 |
1191 | 优
1192 |
1193 |
1194 | Qt::AlignCenter
1195 |
1196 |
1197 |
1198 |
1199 |
1200 |
1201 | -
1202 |
1203 |
1204 |
1205 | 0
1206 |
1207 |
1208 | 5
1209 |
1210 |
1211 | 5
1212 |
1213 |
-
1214 |
1215 |
1216 |
1217 | 0
1218 | 80
1219 |
1220 |
1221 |
1222 |
1223 | 10000
1224 | 10000
1225 |
1226 |
1227 |
1228 | border-bottom-left-radius: 0px;
1229 | border-bottom-right-radius: 0px;
1230 |
1231 |
1232 |
1233 |
1234 |
1235 | Qt::AlignCenter
1236 |
1237 |
1238 |
1239 | -
1240 |
1241 |
1242 |
1243 | 0
1244 | 80
1245 |
1246 |
1247 |
1248 |
1249 | 10000
1250 | 10000
1251 |
1252 |
1253 |
1254 | border-top-left-radius: 0px;
1255 | border-top-right-radius: 0px;
1256 |
1257 |
1258 |
1259 |
1260 |
1261 | Qt::AlignCenter
1262 |
1263 |
1264 |
1265 |
1266 |
1267 |
1268 | -
1269 |
1270 |
1271 |
1272 | 0
1273 |
1274 |
-
1275 |
1276 |
1277 | border-bottom-left-radius: 0px;
1278 | border-bottom-right-radius: 0px;
1279 |
1280 |
1281 | 东风
1282 |
1283 |
1284 | Qt::AlignCenter
1285 |
1286 |
1287 |
1288 | -
1289 |
1290 |
1291 | border-bottom-left-radius: 0px;
1292 | border-bottom-right-radius: 0px;
1293 |
1294 |
1295 | 东北风
1296 |
1297 |
1298 | Qt::AlignCenter
1299 |
1300 |
1301 |
1302 | -
1303 |
1304 |
1305 | border-bottom-left-radius: 0px;
1306 | border-bottom-right-radius: 0px;
1307 |
1308 |
1309 | 西北风
1310 |
1311 |
1312 | Qt::AlignCenter
1313 |
1314 |
1315 |
1316 | -
1317 |
1318 |
1319 | border-bottom-left-radius: 0px;
1320 | border-bottom-right-radius: 0px;
1321 |
1322 |
1323 | 西北风
1324 |
1325 |
1326 | Qt::AlignCenter
1327 |
1328 |
1329 |
1330 | -
1331 |
1332 |
1333 | border-bottom-left-radius: 0px;
1334 | border-bottom-right-radius: 0px;
1335 |
1336 |
1337 | 东南风
1338 |
1339 |
1340 | Qt::AlignCenter
1341 |
1342 |
1343 |
1344 | -
1345 |
1346 |
1347 | border-bottom-left-radius: 0px;
1348 | border-bottom-right-radius: 0px;
1349 |
1350 |
1351 | 西风
1352 |
1353 |
1354 | Qt::AlignCenter
1355 |
1356 |
1357 |
1358 | -
1359 |
1360 |
1361 | border-top-left-radius: 0px;
1362 | border-top-right-radius: 0px;
1363 | color: rgb(240, 240, 240);
1364 |
1365 |
1366 | 2级
1367 |
1368 |
1369 | Qt::AlignCenter
1370 |
1371 |
1372 |
1373 | -
1374 |
1375 |
1376 | border-top-left-radius: 0px;
1377 | border-top-right-radius: 0px;
1378 | color: rgb(240, 240, 240);
1379 |
1380 |
1381 | 3级
1382 |
1383 |
1384 | Qt::AlignCenter
1385 |
1386 |
1387 |
1388 | -
1389 |
1390 |
1391 | border-top-left-radius: 0px;
1392 | border-top-right-radius: 0px;
1393 | color: rgb(240, 240, 240);
1394 |
1395 |
1396 | 2级
1397 |
1398 |
1399 | Qt::AlignCenter
1400 |
1401 |
1402 |
1403 | -
1404 |
1405 |
1406 | border-top-left-radius: 0px;
1407 | border-top-right-radius: 0px;
1408 | color: rgb(240, 240, 240);
1409 |
1410 |
1411 | 1级
1412 |
1413 |
1414 | Qt::AlignCenter
1415 |
1416 |
1417 |
1418 | -
1419 |
1420 |
1421 | border-top-left-radius: 0px;
1422 | border-top-right-radius: 0px;
1423 | color: rgb(240, 240, 240);
1424 |
1425 |
1426 | 2级
1427 |
1428 |
1429 | Qt::AlignCenter
1430 |
1431 |
1432 |
1433 | -
1434 |
1435 |
1436 | border-top-left-radius: 0px;
1437 | border-top-right-radius: 0px;
1438 | color: rgb(240, 240, 240);
1439 |
1440 |
1441 | 2级
1442 |
1443 |
1444 | Qt::AlignCenter
1445 |
1446 |
1447 |
1448 |
1449 |
1450 |
1451 |
1452 |
1453 |
1454 |
1455 |
1456 |
1457 |
1458 |
1459 |
1460 |
1461 |
--------------------------------------------------------------------------------
/citywithtemp.cpp:
--------------------------------------------------------------------------------
1 | #include "citywithtemp.h"
2 | #include "ui_citywithtemp.h"
3 | #include
4 |
5 | QString cityName;
6 |
7 | cityWithTemp::cityWithTemp(QWidget *parent) :
8 | QWidget(parent),
9 | ui(new Ui::cityWithTemp)
10 | {
11 | ui->setupUi(this);
12 | }
13 |
14 | cityWithTemp::~cityWithTemp()
15 | {
16 | delete ui;
17 | }
18 |
19 | void cityWithTemp::SetData(QString str1, QString str2,const QString& pic)
20 | {
21 | ui->citylbl->setText(str1);
22 | ui->templbl->setText(str2);
23 |
24 | QPixmap pixmapPic(pic);
25 | int iWidth = ui->piclbl->width();
26 | int iHeight = ui->piclbl->height();
27 | QPixmap pixmapPicFit = pixmapPic.scaled(iWidth, iHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);//饱满填充
28 |
29 | ui->piclbl->setPixmap(pixmapPicFit);
30 | }
31 |
32 | void cityWithTemp::mousePressEvent(QMouseEvent *event)
33 | {
34 | QWidget::mousePressEvent(event);
35 | cityName = ui->citylbl->text();
36 | // qDebug() << cityName;
37 | }
38 |
--------------------------------------------------------------------------------
/citywithtemp.h:
--------------------------------------------------------------------------------
1 | #ifndef CITYWITHTEMP_H
2 | #define CITYWITHTEMP_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class cityWithTemp;
8 | }
9 |
10 | class cityWithTemp : public QWidget
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit cityWithTemp(QWidget *parent = nullptr);
16 | ~cityWithTemp();
17 | void SetData(QString str1,QString str2,const QString& pic);
18 |
19 | protected:
20 | void mousePressEvent(QMouseEvent* event);
21 |
22 | private:
23 | Ui::cityWithTemp *ui;
24 | };
25 |
26 | #endif // CITYWITHTEMP_H
27 |
--------------------------------------------------------------------------------
/citywithtemp.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | cityWithTemp
4 |
5 |
6 |
7 | 0
8 | 0
9 | 320
10 | 50
11 |
12 |
13 |
14 |
15 | 0
16 | 50
17 |
18 |
19 |
20 |
21 | 16777215
22 | 50
23 |
24 |
25 |
26 | Form
27 |
28 |
29 |
30 | 5
31 |
32 |
33 | 5
34 |
35 |
36 | 0
37 |
38 |
39 | 0
40 |
41 |
42 | 0
43 |
44 | -
45 |
46 |
47 |
48 |
49 |
50 | city
51 |
52 |
53 |
54 | -
55 |
56 |
57 |
58 | 60
59 | 16777215
60 |
61 |
62 |
63 | Icon
64 |
65 |
66 |
67 | -
68 |
69 |
70 | temp
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 |
18 | #include "weatherData.h"
19 | #include "ui_mainwindow.h"
20 | #include "weatherTool.h"
21 |
22 | #define INCREMENT 2 //温度每升高或降低1度,y轴坐标的增量
23 | #define POINT_RADIUS 3 //曲线秒点的大小
24 | #define TEXT_OFFSET_X 9 //温度文本相对于x点的偏移
25 | #define TEXT_OFFSET_Y 7 //温度文本相对于y点的偏移
26 |
27 | MainWindow::MainWindow(QWidget* parent)
28 | : QMainWindow(parent), ui(new Ui::MainWindow) {
29 | ui->setupUi(this);
30 |
31 | //设置窗口属性
32 | setWindowFlag(Qt::FramelessWindowHint); // 设置无边框
33 | setFixedSize(width(), height()); // 设置固定窗口大小
34 |
35 | //设置应用图标
36 | setWindowIcon(QIcon(":/res/WeaFor.png"));
37 |
38 | //构建右键菜单
39 | mExitMenu = new QMenu(this);
40 | mExitAct = new QAction();
41 | mExitAct->setText(tr("退出"));
42 | mExitAct->setIcon(QIcon(":/res/close.ico"));
43 | mExitMenu->addAction(mExitAct);
44 | //用lamba函数连接退出按钮,触发就退出该应用
45 | connect(mExitAct, &QAction::triggered, this, [=]() { qApp->exit(0); });
46 |
47 | //天气图标录入
48 | weaType();
49 |
50 | //网络请求
51 | mNetAccessManager = new QNetworkAccessManager(this);
52 | connect(mNetAccessManager,&QNetworkAccessManager::finished,this,&MainWindow::onReplied);
53 |
54 | //直接在构造中请求天气数据
55 | //目前默认为深圳,可更改
56 | getWeatherInfo("深圳");
57 |
58 | //给标签添加事件过滤器
59 | ui->lblHighCurve->installEventFilter(this);
60 | ui->lblLowCurve->installEventFilter(this);
61 |
62 | //选择大洲窗口
63 | connect(ui->Jump,&QPushButton::clicked,this,[=](){
64 | List->setGeometry(this->geometry());
65 | List->show();
66 | this->hide(); //隐藏当前窗口
67 | });
68 |
69 | //链接到全球天气窗口
70 | connect(ui->World,&QPushButton::clicked,this,[=](){
71 | World->setGeometry(this->geometry());
72 | World->show();
73 | this->hide();
74 | });
75 |
76 | //监听返回
77 | connect(List,&WorldListWea::BackButton,this,[=]{
78 | this->setGeometry(List->geometry());
79 | this->show();
80 | List->hide();
81 | });
82 |
83 | connect(World,&AsiaWea::MainBtn,this,[=](){
84 | this->setGeometry(World->geometry());
85 | this->show();
86 | World->hide();
87 | });
88 |
89 | //连接传递城市参数信号和槽
90 | connect(List,SIGNAL(setData(QString)),this,SLOT(receiveData(QString)));
91 | }
92 |
93 | MainWindow::~MainWindow() { delete ui; }
94 |
95 | //重写父类虚函数
96 | //父类中的默认实现是忽略右键菜单时间,重写后就可以
97 | void MainWindow::contextMenuEvent(QContextMenuEvent* event) {
98 | //弹出右键菜单
99 | mExitMenu->exec(QCursor::pos());
100 | event->accept();
101 | }
102 |
103 | void MainWindow::mousePressEvent(QMouseEvent *event)
104 | {
105 | mOffset = event->globalPos() - this->pos();
106 | }
107 |
108 | void MainWindow::mouseMoveEvent(QMouseEvent *event)
109 | {
110 | this->move(event->globalPos() - mOffset);
111 | }
112 |
113 | void MainWindow::getWeatherInfo(QString cityName)
114 | {
115 | QString cityCode = WeatherTool::getCityCode(cityName);
116 | if(cityCode.isEmpty()){
117 | QMessageBox::warning(this,"提示","请检查城市名是否输错,该页面只支持国内。",QMessageBox::Ok);
118 | return;
119 | }
120 | QUrl url("http://t.weather.itboy.net/api/weather/city/" + cityCode);
121 | mNetAccessManager->get(QNetworkRequest(url));
122 | }
123 |
124 | void MainWindow::parseJson(QByteArray &byteArray)
125 | {
126 | QJsonParseError err;
127 | QJsonDocument doc = QJsonDocument::fromJson(byteArray,&err); // 检测json格式
128 | if(err.error != QJsonParseError::NoError){ // Json格式错误
129 | return;
130 | }
131 |
132 | QJsonObject rootObj = doc.object();
133 | // qDebug() << rootObj.value("message").toString();
134 |
135 | //解析日期和城市
136 | mToday.date = rootObj.value("date").toString();
137 | mToday.city = rootObj.value("cityInfo").toObject().value("city").toString();
138 | int index = mToday.city.indexOf("市");
139 | QString result = mToday.city.left(index); // 取出 "市" 前面的子串
140 | mToday.city = result;
141 |
142 | //解析昨天
143 | QJsonObject objData = rootObj.value("data").toObject();
144 |
145 | QJsonObject objYesterday = objData.value("yesterday").toObject();
146 | mDay[0].week = objYesterday.value("week").toString();
147 | mDay[0].date = objYesterday.value("ymd").toString();
148 |
149 | mDay[0].type = objYesterday.value("type").toString();
150 |
151 | QString s;
152 | s = objYesterday.value("high").toString().split(" ").at(1);
153 | s = s.left(s.length() - 1);
154 | mDay[0].high = s.toInt();
155 |
156 | s = objYesterday.value("low").toString().split(" ").at(1);
157 | s = s.left(s.length() - 1);
158 | mDay[0].low = s.toInt();
159 |
160 | //风向风力
161 | mDay[0].fx = objYesterday.value("fx").toString();
162 | mDay[0].fl = objYesterday.value("fl").toString();
163 | //空气质量指数
164 | mDay[0].aqi = objYesterday.value("aqi").toInt();
165 |
166 | //解析预报中的5天数据
167 | QJsonArray forecatArr = objData.value("forecast").toArray();
168 | for(int i = 0;i < 5;i++){
169 | QJsonObject objForecast = forecatArr[i].toObject();
170 | mDay[i + 1].week = objForecast.value("week").toString();
171 | mDay[i + 1].date = objForecast.value("ymd").toString();
172 | //天气类型
173 | mDay[i + 1].type = objForecast.value("type").toString();
174 |
175 | QString s;
176 | s = objForecast.value("high").toString().split(" ").at(1);
177 | s = s.left(s.length() - 1);
178 | mDay[i + 1].high = s.toInt();
179 |
180 | s = objForecast.value("low").toString().split(" ").at(1);
181 | s = s.left(s.length() - 1);
182 | mDay[i + 1].low = s.toInt();
183 |
184 | //风向风力
185 | mDay[i + 1].fx = objForecast.value("fx").toString();
186 | mDay[i + 1].fl = objForecast.value("fl").toString();
187 | //空气质量指数
188 | mDay[i + 1].aqi = objForecast.value("aqi").toInt();
189 | }
190 |
191 | //解析今天的数据
192 | mToday.ganmao = objData.value("ganmao").toString();
193 | mToday.wendu = objData.value("wendu").toString().toInt();
194 | mToday.shidu = objData.value("shidu").toString();
195 | mToday.pm25 = objData.value("pm25").toInt();
196 | mToday.quality = objData.value("quality").toString();
197 | //forecast 中的第一个数组元素,即今天的数据
198 | mToday.type = mDay[1].type;
199 |
200 | mToday.fx = mDay[1].fx;
201 | mToday.fl = mDay[1].fl;
202 |
203 | mToday.high = mDay[1].high;
204 | mToday.low = mDay[1].low;
205 | //更新UI
206 | updateUI();
207 |
208 | //绘制最高最低温度曲线
209 | ui->lblHighCurve->update();
210 | ui->lblLowCurve->update();
211 | }
212 |
213 | void MainWindow::updateUI()
214 | {
215 | //更新日期和城市
216 | ui->lblDate->setText(QDateTime::fromString(mToday.date,"yyyyMMdd").toString("yyyy/MM/dd")
217 | + " " + mDay[1].week);
218 | ui->lblCity->setText(mToday.city);
219 |
220 | //更新今天
221 | ui->lblTypeIcon->setPixmap(mTypeMap[mToday.type]);
222 | ui->lblTemp->setText(QString::number(mToday.wendu) + "°");
223 | ui->lblType->setText(mToday.type);
224 | ui->lblLowHigh->setText(QString::number(mToday.low) + "~"
225 | + QString::number(mToday.high) + "°C");
226 |
227 | ui->lblGanMao->setText("感冒指数:" + mToday.ganmao);
228 | ui->lblWindFx->setText(mToday.fx);
229 | ui->lblWindFl->setText(mToday.fl);
230 |
231 | ui->lblPM25->setText(QString::number(mToday.pm25));
232 |
233 | ui->lblShiDu->setText(mToday.shidu);
234 | ui->lblQuality->setText(mToday.quality);
235 |
236 | //更新六天的数据
237 | for(int i = 0;i < 6;i++){
238 | //更新日期和时间
239 | mWeekList[i]->setText("星期" + mDay[i].week.right(1));
240 | ui->lblWeek0->setText("昨天");
241 | ui->lblWeek1->setText("今天");
242 | ui->lblWeek2->setText("明天");
243 | QStringList ymdList = mDay[i].date.split("-");
244 | mDateList[i]->setText(ymdList[1] + "/" + ymdList[2]);
245 |
246 | //更新天气类型
247 | mTypeList[i]->setText(mDay[i].type);
248 | mTypeIconList[i]->setPixmap(mTypeMap[mDay[i].type]);
249 |
250 | //更新空气质量
251 | if(mDay[i].aqi >0 && mDay[i].aqi <= 50){
252 | mAqiList[i]->setText("优");
253 | mAqiList[i]->setStyleSheet("background-color: rgb(139,195,74);");
254 | }else if(mDay[i].aqi > 50 && mDay[i].aqi <= 100){
255 | mAqiList[i]->setText("良");
256 | mAqiList[i]->setStyleSheet("background-color: rgb(255,170,0);");
257 | }else if(mDay[i].aqi > 100 && mDay[i].aqi <= 150){
258 | mAqiList[i]->setText("轻度");
259 | mAqiList[i]->setStyleSheet("background-color: rgb(255,87,97);");
260 | }else if(mDay[i].aqi > 150 && mDay[i].aqi <= 200){
261 | mAqiList[i]->setText("中度");
262 | mAqiList[i]->setStyleSheet("background-color: rgb(255,17,27);");
263 | }else if(mDay[i].aqi > 150 && mDay[i].aqi <= 200){
264 | mAqiList[i]->setText("重度");
265 | mAqiList[i]->setStyleSheet("background-color: rgb(170,0,0);");
266 | }else{
267 | mAqiList[i]->setText("严重");
268 | mAqiList[i]->setStyleSheet("background-color: rgb(110,0,0);");
269 | }
270 |
271 | //修正了100判断成10的情况
272 | int sdIndex = mToday.shidu.indexOf("%");
273 | QString shiduRes = mToday.shidu.left(sdIndex); // 取出 "市" 前面的子串
274 | // qDebug() << shiduRes;
275 |
276 | if(shiduRes.toInt() > 70){
277 | QPixmap high("://res/humidity.png");
278 | ui->lblShiDuIcon->setPixmap(high);
279 | }
280 | else {
281 | QPixmap low("://res/lowHumidty.png");
282 | ui->lblShiDuIcon->setPixmap(low);
283 | }
284 |
285 | //更新风力、风向
286 | mFxList[i]->setText(mDay[i].fx);
287 | mFlList[i]->setText(mDay[i].fl);
288 | }
289 | QString city = ui->lblCity->text();
290 | QString temp = ui->lblLowHigh->text();
291 | QString type = mTypeMap[mDay[1].type];
292 | emit sendTemp(city,temp,type);
293 | }
294 |
295 | //消息过滤,主要用于重绘子控件,过滤Paint事件
296 | bool MainWindow::eventFilter(QObject *watched, QEvent *event)
297 | {
298 | //绘制最高温度曲线
299 | if(watched == ui->lblHighCurve && event->type() == QEvent::Paint){
300 | paintHighCurve();
301 | }
302 | //绘制最低温度曲线
303 | if(watched == ui->lblLowCurve && event->type() == QEvent::Paint){
304 | paintLowCurve();
305 | }
306 | return QWidget::eventFilter(watched,event);
307 | }
308 |
309 | //绘制温度曲线函数
310 | void MainWindow::paintHighCurve()
311 | {
312 | QPainter painter(ui->lblHighCurve);
313 |
314 | //抗锯齿
315 | painter.setRenderHint(QPainter::Antialiasing,true);
316 |
317 | //获取x坐标
318 | int pointX[6] = {0};
319 | for(int i = 0;i < 6;i++){
320 | pointX[i] = mWeekList[i]->pos().x() + mWeekList[i]->width() / 2;
321 | }
322 |
323 | int tmpSum = 0;
324 | int tmpAvg = 0;
325 | for(int i = 0;i < 6;i++){
326 | tmpSum += mDay[i].high;
327 | }
328 | tmpAvg = tmpSum / 6;
329 |
330 | //获取y坐标
331 | int pointY[6] = {0};
332 | int yCenter = ui->lblHighCurve->height() / 2;
333 | for(int i = 0;i < 6;i++){
334 | pointY[i] = yCenter - ((mDay[i].high - tmpAvg) * INCREMENT);
335 | }
336 |
337 | //绘制
338 | QPen pen = painter.pen();
339 | pen.setWidth(1);
340 | pen.setColor(QColor(255,170,0));
341 | painter.setPen(pen);
342 | painter.setBrush(QColor(255,170,0)); //设置画刷内部填充的颜色
343 |
344 | //画点、写文本
345 | for(int i = 0;i < 6;i++){
346 | painter.drawEllipse(QPoint(pointX[i],pointY[i]),POINT_RADIUS,POINT_RADIUS);
347 | //显示温度文本
348 | painter.drawText(pointX[i] - TEXT_OFFSET_X,pointY[i] - TEXT_OFFSET_Y,
349 | QString::number(mDay[i].high) + "°");
350 | }
351 | for(int i = 0;i < 5;i++){
352 | if(i == 0){
353 | pen.setStyle(Qt::DashLine);
354 | painter.setPen(pen);
355 | }else{
356 | pen.setStyle(Qt::SolidLine);
357 | painter.setPen(pen);
358 | }
359 | painter.drawLine(pointX[i],pointY[i],pointX[i + 1],pointY[i + 1]);
360 | }
361 | }
362 |
363 | void MainWindow::paintLowCurve()
364 | {
365 | QPainter painter(ui->lblLowCurve);
366 |
367 | // 抗锯齿
368 | painter.setRenderHint(QPainter::Antialiasing,true);
369 |
370 | //获取x坐标
371 | int pointX[6] = {0};
372 | for(int i = 0;i < 6;i++){
373 | pointX[i] = mWeekList[i]->pos().x() + mWeekList[i]->width() / 2;
374 | }
375 |
376 | //获取y坐标
377 | int pointY[6] = {0};
378 | int yCenter = ui->lblLowCurve->height() / 2;
379 |
380 | //求平均气温
381 | int tmpSum = 0;
382 | int tmpAvg = 0;
383 | for(int i = 0;i < 6;i++){
384 | tmpSum += mDay[i].low;
385 | }
386 | tmpAvg = tmpSum / 6;
387 |
388 | for(int i = 0;i < 6;i++){
389 | pointY[i] = yCenter - ((mDay[i].low - tmpAvg) * INCREMENT);
390 | }
391 |
392 | //绘制
393 | QPen pen = painter.pen();
394 | pen.setWidth(1);
395 | pen.setColor(QColor(0,255,255));
396 |
397 | painter.setPen(pen);
398 | painter.setBrush(QColor(0,255,255)); //设置画刷内部填充的颜色
399 |
400 | //画点、写文本
401 | for(int i = 0;i < 6;i++){
402 | painter.drawEllipse(QPoint(pointX[i],pointY[i]),POINT_RADIUS,POINT_RADIUS);
403 | //显示温度文本
404 | painter.drawText(pointX[i] - TEXT_OFFSET_X,pointY[i] - TEXT_OFFSET_Y,QString::number(mDay[i].low) + "°");
405 | }
406 | for(int i = 0;i < 5;i++){
407 | if(i == 0){
408 | pen.setStyle(Qt::DashLine);
409 | painter.setPen(pen);
410 | }else{
411 | pen.setStyle(Qt::SolidLine);
412 | painter.setPen(pen);
413 | }
414 | painter.drawLine(pointX[i],pointY[i],pointX[i + 1],pointY[i + 1]);
415 | }
416 | }
417 |
418 | void MainWindow::weaType()
419 | {
420 | //给搜索绑定回车键
421 | ui->btnSearch->setShortcut(Qt::Key_Enter);
422 | ui->btnSearch->setShortcut(Qt::Key_Return);
423 | //将控件添加到控件数组
424 | mWeekList << ui->lblWeek0 << ui->lblWeek1 << ui->lblWeek2 << ui->lblWeek3 << ui->lblWeek4 << ui->lblWeek5;
425 | mDateList << ui->lblDate0 << ui->lblDate1 << ui->lblDate2 << ui->lblDate3 << ui->lblDate4 << ui->lblDate5;
426 |
427 | mTypeList << ui->lblType0 << ui->lblType1 << ui->lblType2 << ui->lblType3 << ui->lblType4 << ui->lblType5;
428 | mTypeIconList << ui->lblTypeIcon0 << ui->lblTypeIcon1 << ui->lblTypeIcon2 << ui->lblTypeIcon3 << ui->lblTypeIcon4 << ui->lblTypeIcon5;
429 |
430 | mAqiList << ui->lblQuality0 << ui->lblQuality1 << ui->lblQuality2 << ui->lblQuality3 << ui->lblQuality4 << ui->lblQuality5;
431 |
432 | mFxList << ui->lblFx0 << ui->lblFx1 << ui->lblFx2 << ui->lblFx3 << ui->lblFx4 << ui->lblFx5;
433 | mFlList << ui->lblFl0 << ui->lblFl1 << ui->lblFl2 << ui->lblFl3 << ui->lblFl4 << ui->lblFl5;
434 | //天气对应图标
435 | mTypeMap.insert("暴雪",":/res/type/BaoXue.png");
436 | mTypeMap.insert("暴雨",":/res/type/BaoYu.png");
437 | mTypeMap.insert("暴雨到暴雪",":/res/type/BaoYuDaoDaBaoYu.png");
438 | mTypeMap.insert("大暴雨",":/res/type/DaBaoYu.png");
439 | mTypeMap.insert("大暴雨到大暴雪",":/res/type/DaBaoYuDaoTeDaBaoYu.png");
440 | mTypeMap.insert("大到暴雪",":/res/type/DaDaoBaoXue.png");
441 | mTypeMap.insert("大到暴雨",":/res/type/DaDaoBaoYu.png");
442 | mTypeMap.insert("大雪",":/res/type/DaXue.png");
443 | mTypeMap.insert("大雨",":/res/type/DaYu.png");
444 | mTypeMap.insert("冻雨",":/res/type/DongYu.png");
445 | mTypeMap.insert("多云",":/res/type/DuoYun.png");
446 | mTypeMap.insert("浮尘",":/res/type/FuChen.png");
447 | mTypeMap.insert("雷阵雨",":/res/type/LeiZhenYu.png");
448 | mTypeMap.insert("雷阵雨伴有冰雹",":/res/type/LeiZhenYuBanYouBingBao.png");
449 | mTypeMap.insert("霾",":/res/type/Mai.png");
450 | mTypeMap.insert("强沙尘暴",":/res/type/QiangShaChenBao.png");
451 | mTypeMap.insert("晴",":/res/type/Qing.png");
452 | mTypeMap.insert("沙尘暴",":/res/type/ShaChenBao.png");
453 | mTypeMap.insert("特大暴雨",":/res/type/TeDaBaoYu.png");
454 | mTypeMap.insert("雾",":/res/type/Wu.png");
455 | mTypeMap.insert("小到中雨",":/res/type/XiaoDaoZhongYu.png");
456 | mTypeMap.insert("小到中雪",":/res/type/XiaoDaoZhongXue.png");
457 | mTypeMap.insert("小雪",":/res/type/XiaoXue.png");
458 | mTypeMap.insert("小雨",":/res/type/XiaoYu.png");
459 | mTypeMap.insert("雪",":/res/type/Xue.png");
460 | mTypeMap.insert("扬沙",":/res/type/YangSha.png");
461 | mTypeMap.insert("阴",":/res/type/Yin.png");
462 | mTypeMap.insert("雨",":/res/type/Yu.png");
463 | mTypeMap.insert("雨夹雪",":/res/type/YuJiaXue.png");
464 | mTypeMap.insert("阵雨",":/res/type/ZhenYu.png");
465 | mTypeMap.insert("阵雪",":/res/type/ZhenXue.png");
466 | mTypeMap.insert("中雨",":/res/type/ZhongYu.png");
467 | mTypeMap.insert("中雪",":/res/type/ZhongXue.png");
468 | }
469 |
470 | void MainWindow::onReplied(QNetworkReply *reply)
471 | {
472 | int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
473 | if(reply->error() != QNetworkReply::NoError || statusCode != 200){
474 | qDebug() << reply->errorString().toLatin1().data();
475 | QMessageBox::warning(this,"天气","请求数据失败",QMessageBox::Ok);
476 | }else{
477 | QByteArray byteArray = reply->readAll();
478 | // qDebug() << "读所有:" << byteArray.data();
479 | parseJson(byteArray);
480 | }
481 | reply->deleteLater();
482 | }
483 |
484 | void MainWindow::on_btnSearch_clicked()
485 | {
486 | QString cityName = ui->leCity->text();
487 | if(cityName == ""){
488 | return;
489 | }
490 | getWeatherInfo(cityName);
491 | }
492 |
493 | //获取数据并且判断是否在国内
494 | void MainWindow::receiveData(QString cityName)
495 | {
496 | QString cityCode = WeatherTool::getCityCode(cityName);
497 | if(cityCode.isEmpty()){
498 | QMessageBox::information(List,"提示","请检查城市名是否输错,该页面只支持国内。",QMessageBox::Ok);
499 | }
500 | else{
501 | QUrl url("http://t.weather.itboy.net/api/weather/city/" + cityCode);
502 | mNetAccessManager->get(QNetworkRequest(url));
503 | connect(this,SIGNAL(sendTemp(QString,QString,QString)),List,SLOT(getTemp(QString,QString,QString)));
504 | List->hide();
505 | this->setGeometry(List->geometry()); //跳转定位问题
506 | this->show();
507 | }
508 | }
509 |
--------------------------------------------------------------------------------
/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include "weatherData.h"
8 | #include "worldlistwea.h"
9 | #include "asiawea.h"
10 | #include
11 | #include
12 | #include
13 |
14 | QT_BEGIN_NAMESPACE
15 | namespace Ui {
16 | class MainWindow;
17 | }
18 | QT_END_NAMESPACE
19 |
20 | class MainWindow : public QMainWindow {
21 | Q_OBJECT
22 |
23 | public:
24 | MainWindow(QWidget* parent = nullptr);
25 | ~MainWindow();
26 | //跳转五大洲的按钮
27 | WorldListWea* List = new WorldListWea;
28 | AsiaWea* World = new AsiaWea;
29 | cityWithTemp* city = new cityWithTemp;
30 |
31 | protected:
32 | void contextMenuEvent(QContextMenuEvent* event);
33 | void mousePressEvent(QMouseEvent* event);
34 | void mouseMoveEvent(QMouseEvent* event);
35 | //获取天气数据、解析Json、更新UI
36 | void getWeatherInfo(QString cityName);
37 | void parseJson(QByteArray& byteArray);
38 | void updateUI();
39 | //重写父类的eventFilter方法
40 | bool eventFilter(QObject* watched,QEvent* event);
41 | void paintHighCurve();
42 | void paintLowCurve();
43 | void weaType();
44 |
45 | signals:
46 | void sendTemp(QString city,QString temp,QString type);
47 |
48 | private slots:
49 | void on_btnSearch_clicked();
50 | void receiveData(QString str);
51 |
52 | private:
53 | void onReplied(QNetworkReply* reply);
54 |
55 | private:
56 | Ui::MainWindow* ui;
57 | QMenu* mExitMenu; // 退出菜单
58 | QAction* mExitAct; // 菜单项(退出)
59 | QPoint mOffset; //窗口移动时,鼠标与左上角的偏移
60 | QNetworkAccessManager* mNetAccessManager;
61 |
62 | Today mToday;
63 | Day mDay[6];
64 |
65 | //星期和日期
66 | QList mWeekList;
67 | QList mDateList;
68 |
69 | //天气和图标
70 | QList mTypeList;
71 | QList mTypeIconList;
72 |
73 | // 质量指数
74 | QList mAqiList;
75 |
76 | //风力风向
77 | QList mFxList;
78 | QList mFlList;
79 |
80 | QMapmTypeMap;
81 |
82 | };
83 | #endif // MAINWINDOW_H
84 |
--------------------------------------------------------------------------------
/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 450
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 0
21 | 0
22 | 800
23 | 500
24 |
25 |
26 |
27 | QWidget#widget{
28 | border-image: url(:/res/bg.jpg);
29 | }
30 |
31 | QLabel {
32 | font: 25 10pt "微软雅黑";
33 | border-radius: 4px;
34 | background-color: rgba(60, 60, 60, 100);
35 | color: rgb(255, 255, 255);
36 | }
37 |
38 |
39 |
40 |
41 | 10
42 | 70
43 | 341
44 | 121
45 |
46 |
47 |
48 | background-color: rgba(157, 133, 255, 0);
49 | border-radius: 15px
50 |
51 |
52 |
53 | 8
54 |
55 | -
56 |
57 |
58 |
59 | 110
60 | 110
61 |
62 |
63 |
64 |
65 | 110
66 | 110
67 |
68 |
69 |
70 | background-color: rgba(255, 255, 255, 0);
71 |
72 |
73 |
74 |
75 |
76 | :/res/type/DuoYun.png
77 |
78 |
79 | true
80 |
81 |
82 | Qt::AlignCenter
83 |
84 |
85 |
86 | -
87 |
88 |
89 | 0
90 |
91 |
-
92 |
93 |
-
94 |
95 |
96 |
97 | Arial
98 | 50
99 | 50
100 | false
101 | false
102 |
103 |
104 |
105 | color: rgb(255, 255, 255);
106 | font: 50pt "Arial";
107 | background-color: rgba(0, 255, 255, 0);
108 |
109 |
110 | 29°
111 |
112 |
113 | true
114 |
115 |
116 | Qt::AlignCenter
117 |
118 |
119 |
120 | -
121 |
122 |
123 | Qt::Horizontal
124 |
125 |
126 |
127 | 40
128 | 20
129 |
130 |
131 |
132 |
133 | -
134 |
135 |
136 | 0
137 |
138 |
139 | 40
140 |
141 |
-
142 |
143 |
144 | font: 12pt "Microsoft YaHei UI";
145 | background-color: rgba(255, 255, 255,0);
146 |
147 |
148 | 北京
149 |
150 |
151 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | -
160 |
161 |
162 | 6
163 |
164 |
165 | QLayout::SetDefaultConstraint
166 |
167 |
-
168 |
169 |
170 |
171 | 0
172 | 0
173 |
174 |
175 |
176 | background-color: rgba(255, 255, 255,0);
177 | font: 12pt "微软雅黑";
178 |
179 |
180 | 晴转多云
181 |
182 |
183 | true
184 |
185 |
186 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
187 |
188 |
189 |
190 | -
191 |
192 |
193 |
194 | 0
195 | 15
196 |
197 |
198 |
199 |
200 | 16777215
201 | 15
202 |
203 |
204 |
205 | color: rgb(255, 0, 0);
206 |
207 |
208 | Qt::Vertical
209 |
210 |
211 |
212 | -
213 |
214 |
215 | background-color: rgba(255, 255, 255,0);
216 | font: 12pt "微软雅黑";
217 |
218 |
219 | 19°~31°
220 |
221 |
222 | Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
223 |
224 |
225 |
226 | -
227 |
228 |
229 | Qt::Horizontal
230 |
231 |
232 |
233 | 40
234 | 20
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 | 0
249 | 0
250 | 801
251 | 49
252 |
253 |
254 |
255 | background-color: rgba(0, 170, 255,0);
256 |
257 |
258 |
259 | 15
260 |
261 |
262 | 20
263 |
264 | -
265 |
266 |
267 |
268 | 200
269 | 0
270 |
271 |
272 |
273 |
274 | 200
275 | 16777215
276 |
277 |
278 |
279 | font: 14pt "Microsoft YaHei UI";
280 | background-color: rgb(255, 255, 255);
281 | border-radius: 4px;
282 | padding: 1px 5px
283 |
284 |
285 | 城市
286 |
287 |
288 |
289 | -
290 |
291 |
292 | background-color: rgba(0, 0, 0,1);
293 |
294 |
295 |
296 |
297 |
298 |
299 | :/res/Search.png:/res/Search.png
300 |
301 |
302 |
303 | -
304 |
305 |
306 | background-color: rgba(0, 0, 0,1);
307 |
308 |
309 |
310 |
311 |
312 |
313 | :/res/list.png:/res/list.png
314 |
315 |
316 |
317 | -
318 |
319 |
320 | background-color: rgba(0, 0, 0,1);
321 |
322 |
323 |
324 |
325 |
326 |
327 | :/res/world2.png:/res/world2.png
328 |
329 |
330 |
331 | -
332 |
333 |
334 | Qt::Horizontal
335 |
336 |
337 |
338 | 309
339 | 20
340 |
341 |
342 |
343 |
344 | -
345 |
346 |
347 | font: 20pt "Arial";
348 | background-color: rgba(255, 255, 255,0);
349 |
350 |
351 | 2023/03/15 星期四
352 |
353 |
354 | Qt::AlignCenter
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 | 10
364 | 190
365 | 341
366 | 241
367 |
368 |
369 |
370 | -
371 |
372 |
373 | Qt::Vertical
374 |
375 |
376 |
377 | 20
378 | 10
379 |
380 |
381 |
382 |
383 | -
384 |
385 |
386 | background-color: rgba(60,6 0,6 0, 0);
387 | padding-left: 5px;
388 | padding-right: 5px;
389 |
390 |
391 | 感冒指数:儿童、老年人及心脏、呼吸系统疾病患者人群应减少长时间或高强度户外锻炼
392 |
393 |
394 | true
395 |
396 |
397 |
398 | -
399 |
400 |
401 | background-color: rgb(255, 182, 193);
402 | border-radius: 15px
403 |
404 |
405 |
406 | 40
407 |
408 |
409 | 25
410 |
411 |
412 | 40
413 |
414 |
415 | 25
416 |
417 |
418 | 50
419 |
420 |
421 | 20
422 |
423 |
-
424 |
425 |
426 | 0
427 |
428 |
-
429 |
430 |
431 |
432 | 40
433 | 40
434 |
435 |
436 |
437 |
438 | 40
439 | 40
440 |
441 |
442 |
443 | background-color: rgba(255, 255, 255, 0);
444 |
445 |
446 |
447 |
448 |
449 | :/res/wind.png
450 |
451 |
452 | true
453 |
454 |
455 | Qt::AlignCenter
456 |
457 |
458 |
459 | -
460 |
461 |
-
462 |
463 |
464 | background-color: rgba(255, 255, 255,0);
465 | font: 10pt "微软雅黑";
466 |
467 |
468 | 西北风
469 |
470 |
471 | Qt::AlignCenter
472 |
473 |
474 |
475 | -
476 |
477 |
478 | background-color: rgba(255, 255, 255,0);
479 | font: 10pt "微软雅黑";
480 |
481 |
482 | 3级
483 |
484 |
485 | Qt::AlignCenter
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 | -
494 |
495 |
496 | 0
497 |
498 |
-
499 |
500 |
501 |
502 | 40
503 | 40
504 |
505 |
506 |
507 |
508 | 40
509 | 40
510 |
511 |
512 |
513 | background-color: rgba(255, 255, 255, 0);
514 |
515 |
516 |
517 |
518 |
519 | :/res/pm25.png
520 |
521 |
522 | true
523 |
524 |
525 | Qt::AlignCenter
526 |
527 |
528 |
529 | -
530 |
531 |
-
532 |
533 |
534 | background-color: rgba(255, 255, 255,0);
535 | font: 10pt "微软雅黑";
536 |
537 |
538 | PM2.5
539 |
540 |
541 | Qt::AlignCenter
542 |
543 |
544 |
545 | -
546 |
547 |
548 | background-color: rgba(255, 255, 255,0);
549 | font: 10pt "微软雅黑";
550 |
551 |
552 | 10
553 |
554 |
555 | Qt::AlignCenter
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 | -
564 |
565 |
566 | 0
567 |
568 |
-
569 |
570 |
571 |
572 | 40
573 | 40
574 |
575 |
576 |
577 |
578 | 40
579 | 40
580 |
581 |
582 |
583 | background-color: rgba(255, 255, 255, 0);
584 |
585 |
586 |
587 |
588 |
589 | :/res/humidity.png
590 |
591 |
592 | true
593 |
594 |
595 | Qt::AlignCenter
596 |
597 |
598 |
599 | -
600 |
601 |
-
602 |
603 |
604 | background-color: rgba(255, 255, 255,0);
605 | font: 10pt "微软雅黑";
606 |
607 |
608 | 湿度
609 |
610 |
611 | Qt::AlignCenter
612 |
613 |
614 |
615 | -
616 |
617 |
618 | background-color: rgba(255, 255, 255,0);
619 | font: 10pt "微软雅黑";
620 |
621 |
622 | 60%
623 |
624 |
625 | Qt::AlignCenter
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 | -
634 |
635 |
636 | 0
637 |
638 |
-
639 |
640 |
641 |
642 | 40
643 | 40
644 |
645 |
646 |
647 |
648 | 40
649 | 40
650 |
651 |
652 |
653 | false
654 |
655 |
656 | background-color: rgba(255, 255, 255, 0);
657 |
658 |
659 |
660 |
661 |
662 | :/res/aqi.png
663 |
664 |
665 | true
666 |
667 |
668 | Qt::AlignCenter
669 |
670 |
671 | false
672 |
673 |
674 | -1
675 |
676 |
677 |
678 | -
679 |
680 |
-
681 |
682 |
683 | false
684 |
685 |
686 | background-color: rgba(255, 255, 255,0);
687 | font: 10pt "微软雅黑";
688 |
689 |
690 | 空气质量
691 |
692 |
693 | Qt::AlignCenter
694 |
695 |
696 |
697 | -
698 |
699 |
700 | false
701 |
702 |
703 | background-color: rgba(255, 255, 255,0);
704 | font: 10pt "微软雅黑";
705 |
706 |
707 | 优
708 |
709 |
710 | Qt::AlignCenter
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 | 360
727 | 40
728 | 451
729 | 411
730 |
731 |
732 |
733 |
734 | 0
735 |
736 | -
737 |
738 |
739 | QLabel {
740 | background-color: rgba(0, 200, 200, 200);
741 | border-radius: 4px;
742 | }
743 |
744 |
745 |
746 | 6
747 |
748 |
749 | 0
750 |
751 |
-
752 |
753 |
754 | border-bottom-left-radius: 0px;
755 | border-bottom-right-radius: 0px;
756 |
757 |
758 | 昨天
759 |
760 |
761 | Qt::AlignCenter
762 |
763 |
764 |
765 | -
766 |
767 |
768 | border-bottom-left-radius: 0px;
769 | border-bottom-right-radius: 0px;
770 |
771 |
772 | 今天
773 |
774 |
775 | Qt::AlignCenter
776 |
777 |
778 |
779 | -
780 |
781 |
782 | border-bottom-left-radius: 0px;
783 | border-bottom-right-radius: 0px;
784 |
785 |
786 | 明天
787 |
788 |
789 | Qt::AlignCenter
790 |
791 |
792 |
793 | -
794 |
795 |
796 | border-bottom-left-radius: 0px;
797 | border-bottom-right-radius: 0px;
798 |
799 |
800 | 周四
801 |
802 |
803 | Qt::AlignCenter
804 |
805 |
806 |
807 | -
808 |
809 |
810 | border-bottom-left-radius: 0px;
811 | border-bottom-right-radius: 0px;
812 |
813 |
814 | 周五
815 |
816 |
817 | Qt::AlignCenter
818 |
819 |
820 |
821 | -
822 |
823 |
824 | border-bottom-left-radius: 0px;
825 | border-bottom-right-radius: 0px;
826 |
827 |
828 | 周六
829 |
830 |
831 | Qt::AlignCenter
832 |
833 |
834 |
835 | -
836 |
837 |
838 | border-top-left-radius: 0px;
839 | border-top-right-radius: 0px;
840 | color: rgb(240, 240, 240);
841 |
842 |
843 | 01/01
844 |
845 |
846 | Qt::AlignCenter
847 |
848 |
849 |
850 | -
851 |
852 |
853 | border-top-left-radius: 0px;
854 | border-top-right-radius: 0px;
855 | color: rgb(240, 240, 240);
856 |
857 |
858 | 01/02
859 |
860 |
861 | Qt::AlignCenter
862 |
863 |
864 |
865 | -
866 |
867 |
868 | border-top-left-radius: 0px;
869 | border-top-right-radius: 0px;
870 | color: rgb(240, 240, 240);
871 |
872 |
873 | 01/03
874 |
875 |
876 | Qt::AlignCenter
877 |
878 |
879 |
880 | -
881 |
882 |
883 | border-top-left-radius: 0px;
884 | border-top-right-radius: 0px;
885 | color: rgb(240, 240, 240);
886 |
887 |
888 | 01/04
889 |
890 |
891 | Qt::AlignCenter
892 |
893 |
894 |
895 | -
896 |
897 |
898 | border-top-left-radius: 0px;
899 | border-top-right-radius: 0px;
900 | color: rgb(240, 240, 240);
901 |
902 |
903 | 01/05
904 |
905 |
906 | Qt::AlignCenter
907 |
908 |
909 |
910 | -
911 |
912 |
913 | border-top-left-radius: 0px;
914 | border-top-right-radius: 0px;
915 | color: rgb(240, 240, 240);
916 |
917 |
918 | 01/06
919 |
920 |
921 | Qt::AlignCenter
922 |
923 |
924 |
925 |
926 |
927 |
928 | -
929 |
930 |
931 | QLabel {
932 | background-color: rgba(60, 60, 60, 100);
933 | border-radius: 4px;
934 | }
935 |
936 |
937 |
938 | 5
939 |
940 |
941 | 5
942 |
943 |
944 | 0
945 |
946 |
-
947 |
948 |
949 | border-bottom-left-radius: 0px;
950 | border-bottom-right-radius: 0px;
951 |
952 |
953 |
954 |
955 |
956 | :/res/type/DuoYun.png
957 |
958 |
959 | Qt::AlignCenter
960 |
961 |
962 |
963 | -
964 |
965 |
966 |
967 | 0
968 | 0
969 |
970 |
971 |
972 |
973 | 1000
974 | 1000
975 |
976 |
977 |
978 | border-bottom-left-radius: 0px;
979 | border-bottom-right-radius: 0px;
980 |
981 |
982 |
983 |
984 |
985 | :/res/type/Qing.png
986 |
987 |
988 | Qt::AlignCenter
989 |
990 |
991 |
992 | -
993 |
994 |
995 | border-bottom-left-radius: 0px;
996 | border-bottom-right-radius: 0px;
997 |
998 |
999 |
1000 |
1001 |
1002 | :/res/type/DuoYun.png
1003 |
1004 |
1005 | Qt::AlignCenter
1006 |
1007 |
1008 |
1009 | -
1010 |
1011 |
1012 | border-top-left-radius: 0px;
1013 | border-top-right-radius: 0px;
1014 |
1015 |
1016 | 晴
1017 |
1018 |
1019 | Qt::AlignCenter
1020 |
1021 |
1022 |
1023 | -
1024 |
1025 |
1026 | border-top-left-radius: 0px;
1027 | border-top-right-radius: 0px;
1028 |
1029 |
1030 | 多云
1031 |
1032 |
1033 | Qt::AlignCenter
1034 |
1035 |
1036 |
1037 | -
1038 |
1039 |
1040 | border-bottom-left-radius: 0px;
1041 | border-bottom-right-radius: 0px;
1042 |
1043 |
1044 |
1045 |
1046 |
1047 | :/res/type/BaoYu.png
1048 |
1049 |
1050 | Qt::AlignCenter
1051 |
1052 |
1053 |
1054 | -
1055 |
1056 |
1057 | border-top-left-radius: 0px;
1058 | border-top-right-radius: 0px;
1059 |
1060 |
1061 | 暴雨
1062 |
1063 |
1064 | Qt::AlignCenter
1065 |
1066 |
1067 |
1068 | -
1069 |
1070 |
1071 | border-top-left-radius: 0px;
1072 | border-top-right-radius: 0px;
1073 |
1074 |
1075 | 中雨
1076 |
1077 |
1078 | Qt::AlignCenter
1079 |
1080 |
1081 |
1082 | -
1083 |
1084 |
1085 | border-bottom-left-radius: 0px;
1086 | border-bottom-right-radius: 0px;
1087 |
1088 |
1089 |
1090 |
1091 |
1092 | :/res/type/XiaoYu.png
1093 |
1094 |
1095 | Qt::AlignCenter
1096 |
1097 |
1098 |
1099 | -
1100 |
1101 |
1102 | border-top-left-radius: 0px;
1103 | border-top-right-radius: 0px;
1104 |
1105 |
1106 | 多云
1107 |
1108 |
1109 | Qt::AlignCenter
1110 |
1111 |
1112 |
1113 | -
1114 |
1115 |
1116 | border-bottom-left-radius: 0px;
1117 | border-bottom-right-radius: 0px;
1118 |
1119 |
1120 |
1121 |
1122 |
1123 | :/res/type/ZhongYu.png
1124 |
1125 |
1126 | Qt::AlignCenter
1127 |
1128 |
1129 |
1130 | -
1131 |
1132 |
1133 | border-top-left-radius: 0px;
1134 | border-top-right-radius: 0px;
1135 |
1136 |
1137 | 小雨
1138 |
1139 |
1140 | Qt::AlignCenter
1141 |
1142 |
1143 |
1144 |
1145 |
1146 |
1147 | -
1148 |
1149 |
1150 |
1151 | 5
1152 |
1153 |
1154 | 5
1155 |
1156 |
-
1157 |
1158 |
1159 | background-color: rgb(121, 184, 0);
1160 | padding:8px;
1161 |
1162 |
1163 | 优
1164 |
1165 |
1166 | Qt::AlignCenter
1167 |
1168 |
1169 |
1170 | -
1171 |
1172 |
1173 | background-color: rgb(255, 187, 23);
1174 |
1175 |
1176 | 良
1177 |
1178 |
1179 | Qt::AlignCenter
1180 |
1181 |
1182 |
1183 | -
1184 |
1185 |
1186 | background-color: rgb(255, 87, 97);
1187 |
1188 |
1189 | 轻度
1190 |
1191 |
1192 | Qt::AlignCenter
1193 |
1194 |
1195 |
1196 | -
1197 |
1198 |
1199 | background-color: rgb(235, 17, 27);
1200 |
1201 |
1202 | 中度
1203 |
1204 |
1205 | Qt::AlignCenter
1206 |
1207 |
1208 |
1209 | -
1210 |
1211 |
1212 | background-color: rgb(170, 0, 0);
1213 |
1214 |
1215 | 重度
1216 |
1217 |
1218 | Qt::AlignCenter
1219 |
1220 |
1221 |
1222 | -
1223 |
1224 |
1225 | background-color: rgb(110, 0, 0);
1226 |
1227 |
1228 | 严重
1229 |
1230 |
1231 | Qt::AlignCenter
1232 |
1233 |
1234 |
1235 |
1236 |
1237 |
1238 | -
1239 |
1240 |
1241 |
1242 | 0
1243 |
1244 |
1245 | 5
1246 |
1247 |
1248 | 5
1249 |
1250 |
-
1251 |
1252 |
1253 |
1254 | 0
1255 | 80
1256 |
1257 |
1258 |
1259 |
1260 | 10000
1261 | 10000
1262 |
1263 |
1264 |
1265 | border-bottom-left-radius: 0px;
1266 | border-bottom-right-radius: 0px;
1267 |
1268 |
1269 |
1270 |
1271 |
1272 | Qt::AlignCenter
1273 |
1274 |
1275 |
1276 | -
1277 |
1278 |
1279 |
1280 | 0
1281 | 80
1282 |
1283 |
1284 |
1285 |
1286 | 10000
1287 | 10000
1288 |
1289 |
1290 |
1291 | border-top-left-radius: 0px;
1292 | border-top-right-radius: 0px;
1293 |
1294 |
1295 |
1296 |
1297 |
1298 | Qt::AlignCenter
1299 |
1300 |
1301 |
1302 |
1303 |
1304 |
1305 | -
1306 |
1307 |
1308 |
1309 | 0
1310 |
1311 |
-
1312 |
1313 |
1314 | border-bottom-left-radius: 0px;
1315 | border-bottom-right-radius: 0px;
1316 |
1317 |
1318 | 东风
1319 |
1320 |
1321 | Qt::AlignCenter
1322 |
1323 |
1324 |
1325 | -
1326 |
1327 |
1328 | border-bottom-left-radius: 0px;
1329 | border-bottom-right-radius: 0px;
1330 |
1331 |
1332 | 东北风
1333 |
1334 |
1335 | Qt::AlignCenter
1336 |
1337 |
1338 |
1339 | -
1340 |
1341 |
1342 | border-bottom-left-radius: 0px;
1343 | border-bottom-right-radius: 0px;
1344 |
1345 |
1346 | 西北风
1347 |
1348 |
1349 | Qt::AlignCenter
1350 |
1351 |
1352 |
1353 | -
1354 |
1355 |
1356 | border-bottom-left-radius: 0px;
1357 | border-bottom-right-radius: 0px;
1358 |
1359 |
1360 | 西北风
1361 |
1362 |
1363 | Qt::AlignCenter
1364 |
1365 |
1366 |
1367 | -
1368 |
1369 |
1370 | border-bottom-left-radius: 0px;
1371 | border-bottom-right-radius: 0px;
1372 |
1373 |
1374 | 东南风
1375 |
1376 |
1377 | Qt::AlignCenter
1378 |
1379 |
1380 |
1381 | -
1382 |
1383 |
1384 | border-bottom-left-radius: 0px;
1385 | border-bottom-right-radius: 0px;
1386 |
1387 |
1388 | 西风
1389 |
1390 |
1391 | Qt::AlignCenter
1392 |
1393 |
1394 |
1395 | -
1396 |
1397 |
1398 | border-top-left-radius: 0px;
1399 | border-top-right-radius: 0px;
1400 | color: rgb(240, 240, 240);
1401 |
1402 |
1403 | 2级
1404 |
1405 |
1406 | Qt::AlignCenter
1407 |
1408 |
1409 |
1410 | -
1411 |
1412 |
1413 | border-top-left-radius: 0px;
1414 | border-top-right-radius: 0px;
1415 | color: rgb(240, 240, 240);
1416 |
1417 |
1418 | 3级
1419 |
1420 |
1421 | Qt::AlignCenter
1422 |
1423 |
1424 |
1425 | -
1426 |
1427 |
1428 | border-top-left-radius: 0px;
1429 | border-top-right-radius: 0px;
1430 | color: rgb(240, 240, 240);
1431 |
1432 |
1433 | 2级
1434 |
1435 |
1436 | Qt::AlignCenter
1437 |
1438 |
1439 |
1440 | -
1441 |
1442 |
1443 | border-top-left-radius: 0px;
1444 | border-top-right-radius: 0px;
1445 | color: rgb(240, 240, 240);
1446 |
1447 |
1448 | 1级
1449 |
1450 |
1451 | Qt::AlignCenter
1452 |
1453 |
1454 |
1455 | -
1456 |
1457 |
1458 | border-top-left-radius: 0px;
1459 | border-top-right-radius: 0px;
1460 | color: rgb(240, 240, 240);
1461 |
1462 |
1463 | 2级
1464 |
1465 |
1466 | Qt::AlignCenter
1467 |
1468 |
1469 |
1470 | -
1471 |
1472 |
1473 | border-top-left-radius: 0px;
1474 | border-top-right-radius: 0px;
1475 | color: rgb(240, 240, 240);
1476 |
1477 |
1478 | 2级
1479 |
1480 |
1481 | Qt::AlignCenter
1482 |
1483 |
1484 |
1485 |
1486 |
1487 |
1488 |
1489 |
1490 |
1491 |
1492 |
1493 |
1494 |
1495 |
1496 |
1497 |
1498 |
--------------------------------------------------------------------------------
/newWeather.pro:
--------------------------------------------------------------------------------
1 | QT += core gui network
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++17
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp \
21 | worldlistwea.cpp \
22 | asiawea.cpp \
23 | citywithtemp.cpp \
24 |
25 | HEADERS += \
26 | mainwindow.h \
27 | weatherData.h \
28 | weatherTool.h \
29 | worldlistwea.h \
30 | asiawea.h \
31 | citywithtemp.h
32 |
33 | FORMS += \
34 | mainwindow.ui \
35 | worldlistwea.ui \
36 | asiawea.ui \
37 | citywithtemp.ui
38 |
39 | # Default rules for deployment.
40 | qnx: target.path = /tmp/$${TARGET}/bin
41 | else: unix:!android: target.path = /opt/$${TARGET}/bin
42 | !isEmpty(target.path): INSTALLS += target
43 |
44 | RESOURCES += \
45 | res.qrc
46 |
47 | DISTFILES += \
48 | citycode-2019-08-23.json
49 |
--------------------------------------------------------------------------------
/newWeather.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {2271f1a7-0d06-4e7c-8647-d8dcf8a85742}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 | -fno-delayed-template-parsing
60 |
61 | true
62 |
63 |
64 |
65 | ProjectExplorer.Project.Target.0
66 |
67 | Desktop Qt 5.9.9 MinGW 32bit
68 | Desktop Qt 5.9.9 MinGW 32bit
69 | qt.qt5.599.win32_mingw53_kit
70 | 0
71 | 0
72 | 0
73 |
74 | D:/qtproject/build-newWeather-Desktop_Qt_5_9_9_MinGW_32bit-Debug
75 |
76 |
77 | true
78 | QtProjectManager.QMakeBuildStep
79 | true
80 |
81 | false
82 | false
83 | false
84 |
85 |
86 | true
87 | Qt4ProjectManager.MakeStep
88 |
89 | false
90 |
91 |
92 | false
93 |
94 | 2
95 | Build
96 | Build
97 | ProjectExplorer.BuildSteps.Build
98 |
99 |
100 |
101 | true
102 | Qt4ProjectManager.MakeStep
103 |
104 | true
105 | clean
106 |
107 | false
108 |
109 | 1
110 | Clean
111 | Clean
112 | ProjectExplorer.BuildSteps.Clean
113 |
114 | 2
115 | false
116 |
117 | Debug
118 | Qt4ProjectManager.Qt4BuildConfiguration
119 | 2
120 |
121 |
122 | D:/qtproject/build-newWeather-Desktop_Qt_5_9_9_MinGW_32bit-Release
123 |
124 |
125 | true
126 | QtProjectManager.QMakeBuildStep
127 | false
128 |
129 | false
130 | false
131 | false
132 |
133 |
134 | true
135 | Qt4ProjectManager.MakeStep
136 |
137 | false
138 |
139 |
140 | false
141 |
142 | 2
143 | Build
144 | Build
145 | ProjectExplorer.BuildSteps.Build
146 |
147 |
148 |
149 | true
150 | Qt4ProjectManager.MakeStep
151 |
152 | true
153 | clean
154 |
155 | false
156 |
157 | 1
158 | Clean
159 | Clean
160 | ProjectExplorer.BuildSteps.Clean
161 |
162 | 2
163 | false
164 |
165 | Release
166 | Qt4ProjectManager.Qt4BuildConfiguration
167 | 0
168 |
169 |
170 | D:/qtproject/build-newWeather-Desktop_Qt_5_9_9_MinGW_32bit-Profile
171 |
172 |
173 | true
174 | QtProjectManager.QMakeBuildStep
175 | true
176 |
177 | false
178 | true
179 | false
180 |
181 |
182 | true
183 | Qt4ProjectManager.MakeStep
184 |
185 | false
186 |
187 |
188 | false
189 |
190 | 2
191 | Build
192 | Build
193 | ProjectExplorer.BuildSteps.Build
194 |
195 |
196 |
197 | true
198 | Qt4ProjectManager.MakeStep
199 |
200 | true
201 | clean
202 |
203 | false
204 |
205 | 1
206 | Clean
207 | Clean
208 | ProjectExplorer.BuildSteps.Clean
209 |
210 | 2
211 | false
212 |
213 | Profile
214 | Qt4ProjectManager.Qt4BuildConfiguration
215 | 0
216 |
217 | 3
218 |
219 |
220 | 0
221 | Deploy
222 | Deploy
223 | ProjectExplorer.BuildSteps.Deploy
224 |
225 | 1
226 | ProjectExplorer.DefaultDeployConfiguration
227 |
228 | 1
229 |
230 |
231 | dwarf
232 |
233 | cpu-cycles
234 |
235 |
236 | 250
237 |
238 | -e
239 | cpu-cycles
240 | --call-graph
241 | dwarf,4096
242 | -F
243 | 250
244 |
245 | -F
246 | true
247 | 4096
248 | false
249 | false
250 | 1000
251 |
252 | true
253 |
254 | false
255 | false
256 | false
257 | false
258 | true
259 | 0.01
260 | 10
261 | true
262 | kcachegrind
263 | 1
264 | 25
265 |
266 | 1
267 | true
268 | false
269 | true
270 | valgrind
271 |
272 | 0
273 | 1
274 | 2
275 | 3
276 | 4
277 | 5
278 | 6
279 | 7
280 | 8
281 | 9
282 | 10
283 | 11
284 | 12
285 | 13
286 | 14
287 |
288 | 2
289 |
290 | Qt4ProjectManager.Qt4RunConfiguration:D:/qtproject/newWeather/newWeather.pro
291 | D:/qtproject/newWeather/newWeather.pro
292 |
293 | false
294 |
295 | false
296 | true
297 | true
298 | false
299 | false
300 | true
301 |
302 | D:/qtproject/build-newWeather-Desktop_Qt_5_9_9_MinGW_32bit-Debug
303 |
304 | 1
305 |
306 |
307 |
308 | ProjectExplorer.Project.TargetCount
309 | 1
310 |
311 |
312 | ProjectExplorer.Project.Updater.FileVersion
313 | 22
314 |
315 |
316 | Version
317 | 22
318 |
319 |
320 |
--------------------------------------------------------------------------------
/qt八股文.md:
--------------------------------------------------------------------------------
1 | QImage和QPixMap都是Qt中用于表示图像的类,它们的区别主要在于:
2 |
3 | QImage和QPixMap底层数据的存储方式不同:QImage的像素数据存储在内存中,而QPixMap则是使用显存来存储像素数据。因此,当需要处理大量图像数据时,QImage会占用更多的内存,而QPixMap的处理速度更快,因为它直接使用图形硬件。
4 | QImage和QPixMap的应用场景不同:QImage可以在内存中进行高级图像处理操作,例如将一个图像缩放或者应用滤镜效果,然后将处理后的图像渲染到QPixMap或者QWidget上显示。而QPixMap通常用于直接在窗口或者其他QWidget上绘制位图,例如游戏动画或者用户界面元素。
5 | QImage和QPixMap对透明度的处理方式不同:QPixMap中的像素不支持透明度,如果需要使用透明度,需要将QPixMap和QPainter的compositing模式一起使用。而QImage可以支持不同的透明度设置,对于图像处理上涉及到透明通道的操作,比如将一些图像合并、叠加,会更加便捷。
6 |
7 | 综上所述,QImage和QPixMap在应用场景、像素数据存储方式、透明度处理等方面具有不同的特点。根据实际需求,可以选择合适的类来处理图像。
8 |
9 |
10 | Qt支持6种连接方式,其中前3种最主要:
11 | 1.Qt::AutoConnection(自动方式)
12 | Qt的默认连接方式,如果信号的发出和接收这个信号的对象同属一个线程,那个工作方式与直连方式相同;否则工作方式与排队方式相同。
13 | 2.Qt::DirectConnection(直接连接)(同步)
14 | 当信号发送后,相应的槽函数将立即被调用。emit语句后的代码将在所有槽函数执行完毕后被执行。
15 | 3.Qt::QueuedConnection(排队连接)(异步)
16 | 当信号发出后,排队到信号队列中,需等到接收对象所属线程的事件循环取得控制权时才取得该信号,调用相应的槽函数。emit语句后的代码将在发出信号后立即被执行,无需等待槽函数执行完毕。多线程环境下可使用。
17 | 4.Qt::BlockingQueuedConnection(阻塞连接,信号和槽必须在不同的线程中,否则就产生死锁)
18 | 发送信号后发送者所在的线程会处于阻塞状态 ,直到槽函数运行完。多线程同步环境下可使用。
19 | 5.Qt::UniqueConnection
20 | 与默认工作方式相同,只是不能重复连接相同的信号和槽,因为如果重复连接就会导致一个信号发出,对应槽函数就会执行多次。这个flag可以通过按位或(|)与以上四个结合在一起使用
21 | 6.Qt::AutoCompatConnection
22 | 是为了连接Qt4与Qt3的信号槽机制兼容方式,工作方式与Qt::AutoConnection一样。
23 |
24 | QListWidget是基于Item,而QListView是基于Model的。
25 |
26 |
27 | QLineEdit控件textChanged信号和textEdited信号区别:
28 |
29 | textChanged信号:每当文本改变时,就会发出这个信号。文本参数是新文本。
30 |
31 | 与textEdited()不同,当以编程方式更改文本时,例如,通过调用setText()也会发出此信号。
32 |
33 |
34 |
35 | textEdited信号:每当文本被编辑时,就会发出这个信号。文本参数是新文本。
36 |
37 | 与textChanged()不同,当以编程方式更改文本时,例如,通过调用setText()不会发出此信号。
38 |
39 | Alt+0 显示或者隐藏侧边条,编辑模式下起作用(有时写的函数太长,屏幕不够大,就用这个)
40 |
41 | Ctrl+Space 自动补全(貌似会和输入法的切换冲突)
42 |
43 | ESc 切换到编辑模式
44 |
45 | - 修改变量名,并应用到所有使用该变量的地方。
46 |
47 | 将光标移动到需要更改的变量上,按Ctrl + Shift + R,当前变量名称外框为红色时,表示已经已激活全局修改功能,当修改此处变量名称时将一同修改代码中所有使用该变量的变量名。
48 |
49 | - 书签功能
50 |
51 | Qt Creator中有一个叫做书签功能,即在某行代码处进行标记,方便以后找到。书签也可以添加文字标注。Qt中
52 |
53 | 按Ctrl + M 添加/删除书签,
54 |
55 | 按Ctrl + . 查找并移动到下一个标签
56 |
57 | - 分栏显示
58 |
59 | 这个功能只要用 Qt Creator开发基本上都会用到。这个快捷键操作方法比较特别:
60 |
61 | 先按Ctrl + e后松开再按2添加上下布局的分栏
62 |
63 | 先按Ctrl + e后松开再按3添加上下布局的分栏
64 |
65 | 先按Ctrl + e后松开再按1删除所有的分栏
66 |
67 |
68 |
69 | Ctrl + shift + up 将当前行的代码向上移动一行。
70 |
71 | Ctrl + shift + down 将当前行的代码向下移动一行。
72 |
73 | QPixmap主要用于绘图,针对图像显示而最佳化设计;
74 |
75 | QImage主要是为图像I/O、图像访问及像素修改而设计。但若用QPixmap加载大图片的时候,会占用很大内存,适合加载小图片;一个几十K的图片,加载进来后会放大很多倍。
76 |
77 | 若图片过大,可用QImage进行加载,然后转成QPixmap用户绘制,QPixmap绘制效果最好。
78 |
79 | QListWidget是继承QListView,QListView是基于Model的,需要自己来建模(如建立QStringListModel,QSqlTableModel等),保存数据,这样就大大降低了数据冗余,提高了程序的效率,但是需要我们对数据建模有一定的了解,而QListWidget是一个升级版本的QListView,它已经为我们建立了一个数据存储模型QListWidgetItem,操作方便,直接调用addItem即可添加Item项。
80 |
81 | 1、QPixmap依赖于硬件,QImage不依赖;
82 |
83 | 2、QPixmap主要是用于绘图,针对屏幕显示而最佳化设计,QImage主要是为图像IO、图片访问和像素修改设计的。
84 |
85 | 3、总结:当图片比较小的时候,直接使用QPixmap进行加载,画图时无所谓,当图片大的时候如果直接用QPixmap进行加载会占用比较大的内存,所以当图片大的时候用QImage进行加载,然后转成QPixmap绘制。QPixmap绘制效果最好。
86 |
87 | QVariant这个类很神奇,或者说方便。很多时候,需要几种不同的数据类型需要传递,如果用结构体,又不大方便,容器保存的也只是一种数据类型,而QVariant则可以统统搞定。
88 |
89 | 帮助文档上说:The QVariant class acts like a union for the most common Qt data types.。
90 |
91 | QVariant 这个类型充当着最常见的数据类型的联合。
92 |
--------------------------------------------------------------------------------
/res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | res/aqi.png
4 | res/background.png
5 | res/close.png
6 | res/humidity.png
7 | res/pm25.png
8 | res/sunrise.png
9 | res/wind.png
10 | res/type/BaoXue.png
11 | res/type/BaoYu.png
12 | res/type/BaoYuDaoDaBaoYu.png
13 | res/type/DaBaoYu.png
14 | res/type/DaBaoYuDaoTeDaBaoYu.png
15 | res/type/DaDaoBaoXue.png
16 | res/type/DaDaoBaoYu.png
17 | res/type/DaXue.png
18 | res/type/DaYu.png
19 | res/type/DongYu.png
20 | res/type/DuoYun.png
21 | res/type/FuChen.png
22 | res/type/LeiZhenYu.png
23 | res/type/LeiZhenYuBanYouBingBao.png
24 | res/type/Mai.png
25 | res/type/QiangShaChenBao.png
26 | res/type/Qing.png
27 | res/type/ShaChenBao.png
28 | res/type/TeDaBaoYu.png
29 | res/type/undefined.png
30 | res/type/Wu.png
31 | res/type/XiaoDaoZhongXue.png
32 | res/type/XiaoDaoZhongYu.png
33 | res/type/XiaoXue.png
34 | res/type/XiaoYu.png
35 | res/type/Xue.png
36 | res/type/YangSha.png
37 | res/type/Yin.png
38 | res/type/Yu.png
39 | res/type/YuJiaXue.png
40 | res/type/ZhenXue.png
41 | res/type/ZhenYu.png
42 | res/type/ZhongDaoDaXue.png
43 | res/type/ZhongDaoDaYu.png
44 | res/type/ZhongXue.png
45 | res/type/ZhongYu.png
46 | res/bg.jpg
47 | res/bg2.jpg
48 | res/list.png
49 | res/back.png
50 | res/WeaFor.png
51 | res/world2.png
52 | res/Search.png
53 | res/lowHumidty.png
54 |
55 |
56 |
--------------------------------------------------------------------------------
/res/Search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/Search.png
--------------------------------------------------------------------------------
/res/WeaFor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/WeaFor.png
--------------------------------------------------------------------------------
/res/aqi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/aqi.png
--------------------------------------------------------------------------------
/res/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/back.png
--------------------------------------------------------------------------------
/res/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/background.png
--------------------------------------------------------------------------------
/res/bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/bg.jpg
--------------------------------------------------------------------------------
/res/bg2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/bg2.jpg
--------------------------------------------------------------------------------
/res/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/close.png
--------------------------------------------------------------------------------
/res/humidity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/humidity.png
--------------------------------------------------------------------------------
/res/list.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/list.png
--------------------------------------------------------------------------------
/res/lowHumidty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/lowHumidty.png
--------------------------------------------------------------------------------
/res/pm25.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/pm25.png
--------------------------------------------------------------------------------
/res/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/search.png
--------------------------------------------------------------------------------
/res/sunrise.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/sunrise.png
--------------------------------------------------------------------------------
/res/type/BaoXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/BaoXue.png
--------------------------------------------------------------------------------
/res/type/BaoYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/BaoYu.png
--------------------------------------------------------------------------------
/res/type/BaoYuDaoDaBaoYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/BaoYuDaoDaBaoYu.png
--------------------------------------------------------------------------------
/res/type/DaBaoYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/DaBaoYu.png
--------------------------------------------------------------------------------
/res/type/DaBaoYuDaoTeDaBaoYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/DaBaoYuDaoTeDaBaoYu.png
--------------------------------------------------------------------------------
/res/type/DaDaoBaoXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/DaDaoBaoXue.png
--------------------------------------------------------------------------------
/res/type/DaDaoBaoYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/DaDaoBaoYu.png
--------------------------------------------------------------------------------
/res/type/DaXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/DaXue.png
--------------------------------------------------------------------------------
/res/type/DaYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/DaYu.png
--------------------------------------------------------------------------------
/res/type/DongYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/DongYu.png
--------------------------------------------------------------------------------
/res/type/DuoYun.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/DuoYun.png
--------------------------------------------------------------------------------
/res/type/FuChen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/FuChen.png
--------------------------------------------------------------------------------
/res/type/LeiZhenYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/LeiZhenYu.png
--------------------------------------------------------------------------------
/res/type/LeiZhenYuBanYouBingBao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/LeiZhenYuBanYouBingBao.png
--------------------------------------------------------------------------------
/res/type/Mai.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/Mai.png
--------------------------------------------------------------------------------
/res/type/QiangShaChenBao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/QiangShaChenBao.png
--------------------------------------------------------------------------------
/res/type/Qing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/Qing.png
--------------------------------------------------------------------------------
/res/type/ShaChenBao.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/ShaChenBao.png
--------------------------------------------------------------------------------
/res/type/TeDaBaoYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/TeDaBaoYu.png
--------------------------------------------------------------------------------
/res/type/Wu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/Wu.png
--------------------------------------------------------------------------------
/res/type/XiaoDaoZhongXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/XiaoDaoZhongXue.png
--------------------------------------------------------------------------------
/res/type/XiaoDaoZhongYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/XiaoDaoZhongYu.png
--------------------------------------------------------------------------------
/res/type/XiaoXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/XiaoXue.png
--------------------------------------------------------------------------------
/res/type/XiaoYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/XiaoYu.png
--------------------------------------------------------------------------------
/res/type/Xue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/Xue.png
--------------------------------------------------------------------------------
/res/type/YangSha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/YangSha.png
--------------------------------------------------------------------------------
/res/type/Yin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/Yin.png
--------------------------------------------------------------------------------
/res/type/Yu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/Yu.png
--------------------------------------------------------------------------------
/res/type/YuJiaXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/YuJiaXue.png
--------------------------------------------------------------------------------
/res/type/ZhenXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/ZhenXue.png
--------------------------------------------------------------------------------
/res/type/ZhenYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/ZhenYu.png
--------------------------------------------------------------------------------
/res/type/ZhongDaoDaXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/ZhongDaoDaXue.png
--------------------------------------------------------------------------------
/res/type/ZhongDaoDaYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/ZhongDaoDaYu.png
--------------------------------------------------------------------------------
/res/type/ZhongXue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/ZhongXue.png
--------------------------------------------------------------------------------
/res/type/ZhongYu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/ZhongYu.png
--------------------------------------------------------------------------------
/res/type/neige.txt:
--------------------------------------------------------------------------------
1 | qweqwe
2 |
--------------------------------------------------------------------------------
/res/type/undefined.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/type/undefined.png
--------------------------------------------------------------------------------
/res/wind.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/wind.png
--------------------------------------------------------------------------------
/res/world2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EEEugene/qtWeatherForecast/87e4549853b421fda242da8431328e97b5bc2b47/res/world2.png
--------------------------------------------------------------------------------
/weatherData.h:
--------------------------------------------------------------------------------
1 | #ifndef WEATHERDATA_H
2 | #define WEATHERDATA_H
3 |
4 | #include
5 |
6 | class Today{
7 |
8 | public:
9 | Today()
10 | {
11 | date = "2023-03-07";
12 | city = "深圳";
13 |
14 | ganmao = "感冒指数";
15 | wendu = 0;
16 | shidu = "0%";
17 | pm25 = 0;
18 | quality = "无数据";
19 |
20 | type = "多云";
21 | fl = "2级";
22 | fx = "南风";
23 | high = 20;
24 | low = 18;
25 | }
26 | QString date;
27 | QString city;
28 |
29 | QString ganmao;
30 | QString shidu;
31 |
32 | int wendu;
33 | int pm25;
34 |
35 | QString quality;
36 | QString type;
37 |
38 | QString fl;
39 | QString fx;
40 |
41 | int high;
42 | int low;
43 | };
44 |
45 | class Day{
46 | public:
47 | Day(){
48 | date = "2023-03-07";
49 | week = "周二";
50 |
51 | type = "多云";
52 |
53 | high = 0;
54 | low = 0;
55 |
56 | fl = "2级";
57 | fx = "南风";
58 |
59 | aqi = 0;
60 | }
61 | QString date;
62 | QString week;
63 |
64 | QString type;
65 |
66 | int high;
67 | int low;
68 |
69 | QString fl;
70 | QString fx;
71 |
72 | int aqi;
73 | };
74 |
75 | #endif // WEATHERDATA_H
76 |
--------------------------------------------------------------------------------
/weatherTool.h:
--------------------------------------------------------------------------------
1 | #ifndef WEATHERTOOL_H
2 | #define WEATHERTOOL_H
3 |
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 |
14 | class WeatherTool{
15 |
16 | private:
17 | static QMap mCityMaps;
18 |
19 | static void initCityMap(){
20 | QString filePath = "D:/citycode-2019-08-23.json";
21 | QFile file(filePath);
22 | file.open(QIODevice::ReadOnly | QIODevice::Text);
23 | QByteArray json = file.readAll();
24 | file.close();
25 | QJsonParseError err;
26 | QJsonDocument doc = QJsonDocument::fromJson(json,&err);
27 | if(err.error != QJsonParseError::NoError){
28 | return;
29 | }
30 | if(!doc.isArray()){
31 | return;
32 | }
33 | QJsonArray cities = doc.array();
34 | for(int i = 0;i 0){
38 | mCityMaps.insert(city,code);
39 | }
40 | }
41 | }
42 |
43 | public:
44 | static QString getCityCode(QString cityName){
45 | if(mCityMaps.isEmpty()){
46 | initCityMap();
47 | }
48 | QMap::iterator it = mCityMaps.find(cityName);
49 | //
50 | if(it == mCityMaps.end()){
51 | it = mCityMaps.find(cityName + "市");
52 | }
53 | if(it != mCityMaps.end()){
54 | return it.value();
55 | }
56 | return "";
57 | }
58 | };
59 |
60 | QMap WeatherTool::mCityMaps={};
61 |
62 | #endif // WEATHERTOOL_H
63 |
--------------------------------------------------------------------------------
/worldlistwea.cpp:
--------------------------------------------------------------------------------
1 | #include "worldlistwea.h"
2 | #include "ui_worldlistwea.h"
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | extern QString cityName;
20 |
21 | WorldListWea::WorldListWea(QWidget *parent) :
22 | QMainWindow(parent),
23 | ui(new Ui::WorldListWea)
24 | {
25 | ui->setupUi(this);
26 | setWindowFlag(Qt::FramelessWindowHint); // 设置无边框
27 | setFixedSize(width(), height()); // 设置固定窗口大小
28 |
29 | //设置图标
30 | setWindowIcon(QIcon(":/res/WeaFor.png"));
31 |
32 | //构建右键菜单
33 | mExitMenu = new QMenu(this);
34 | mExitAct = new QAction();
35 | mExitAct->setText(tr("退出"));
36 | mExitAct->setIcon(QIcon(":/res/close.ico"));
37 | mExitMenu->addAction(mExitAct);
38 | //用lamba函数连接退出按钮,触发就退出该应用
39 | connect(mExitAct, &QAction::triggered, this, [=]() { qApp->exit(0); });
40 |
41 | connect(ui->backBtn,&QPushButton::clicked,this,[=](){
42 | on_listBtn_clicked();
43 | emit this->BackButton();
44 | });
45 |
46 | setState();
47 | }
48 |
49 | WorldListWea::~WorldListWea()
50 | {
51 | delete ui;
52 | }
53 |
54 | void WorldListWea::contextMenuEvent(QContextMenuEvent *event)
55 | {
56 | //弹出右键菜单
57 | mExitMenu->exec(QCursor::pos());
58 | event->accept();
59 | }
60 |
61 | void WorldListWea::mousePressEvent(QMouseEvent *event)
62 | {
63 | mOffset = event->globalPos() - this->pos();
64 | }
65 |
66 | //重写鼠标移动事件
67 | void WorldListWea::mouseMoveEvent(QMouseEvent *event)
68 | {
69 | this->move(event->globalPos() - mOffset);
70 | }
71 |
72 | //默认情况下先选择五大洲
73 | void WorldListWea::setState()
74 | {
75 | ui->listWidget->hide();
76 | QStringList stateList;
77 | stateList << "亚洲" << "欧洲" << "非洲" << "美洲" << "大洋洲";
78 | ui->stateWidget->addItems(stateList);
79 | }
80 |
81 | void WorldListWea::asiaCity()
82 | {
83 | ui->listWidget->show();
84 | ui->listWidget->clear();
85 | AddItem("东京","13°~19°","://res/type/DuoYun.png");
86 | AddItem("香港","21°~26°","://res/type/Yin.png");
87 | AddItem("广州","25°~28°","://res/type/DuoYun.png");
88 | AddItem("新加坡","26°~31","://res/type/DaYu.png");
89 | AddItem("吉隆坡","18°~21°","://res/type/XiaoYu.png");
90 | AddItem("大阪","13°~17°","://res/type/DuoYun.png");
91 | AddItem("首尔","11°~22°","://res/type/DuoYun.png");
92 | AddItem("上海","16°~27°","://res/type/Qing.png");
93 | AddItem("北京","12°~22°","://res/type/DuoYun.png");
94 | AddItem("深圳","21°~28°","://res/type/DuoYun.png");
95 | }
96 |
97 | void WorldListWea::euCity()
98 | {
99 | ui->listWidget->clear();
100 | ui->listWidget->show();
101 | AddItem("伦敦","4°~13°","://res/type/Yin.png");
102 | AddItem("巴黎","7°~13°","://res/type/Yin.png");
103 | AddItem("莫斯科","8°~20°","://res/type/Yu.png");
104 | AddItem("罗马","9°~20°","://res/type/Qing.png");
105 | AddItem("马德里","10°~28°","://res/type/Qing.png");
106 | AddItem("柏林","6°~10°","://res/type/Yin.png");
107 | AddItem("威尼斯","10°~15°","://res/type/Yin.png");
108 | AddItem("汉堡","4°~8°","://res/type/Yu.png");
109 | AddItem("维也纳","9°~14°","://res/type/Yin.png");
110 | AddItem("米兰","16°~21°","://res/type/Yu.png");
111 | }
112 |
113 | void WorldListWea::afCity()
114 | {
115 | ui->listWidget->clear();
116 | ui->listWidget->show();
117 | AddItem("开罗","17°~28°","://res/type/Qing.png");
118 | AddItem("坎帕拉","11°~25°","://res/type/Qing.png");
119 | AddItem("开普敦","12°~22°","://res/type/Qing.png");
120 | AddItem("内罗毕","17°~24°","://res/type/Yin.png");
121 | AddItem("阿尔及尔","19°~28°","://res/type/Qing.png");
122 | AddItem("拉各斯","28°~30°","://res/type/Yin.png");
123 | AddItem("金沙萨","20°~29°","://res/type/Yu.png");
124 | AddItem("阿比让","20°~25°","://res/type/Qing.png");
125 | AddItem("达喀尔","21°~25°","://res/type/Qing.png");
126 | AddItem("突尼斯","24°~30°","://res/type/Yu.png");
127 | }
128 |
129 | void WorldListWea::naCity()
130 | {
131 | ui->listWidget->clear();
132 | ui->listWidget->show();
133 | AddItem("墨西哥城","13°~26°","://res/type/Qing.png");
134 | AddItem("纽约","6°~11°","://res/type/Yin.png");
135 | AddItem("洛杉矶","7°~18°","://res/type/Qing.png");
136 | AddItem("多伦多","3°~10°","://res/type/Yin.png");
137 | AddItem("芝加哥","4°~9°","://res/type/Yin.png");
138 | AddItem("休斯顿","15°~23°","://res/type/Qing.png");
139 | AddItem("费城","8°~17°","://res/type/DuoYun.png");
140 | AddItem("里约热内卢","16°~24°","://res/type/Qing.png");
141 | AddItem("圣地亚哥","10°~23°","://res/type/Qing.png");
142 | AddItem("圣保罗","4°~13°","://res/type/Qing.png");
143 | }
144 |
145 | void WorldListWea::oaCity()
146 | {
147 | ui->listWidget->clear();
148 | ui->listWidget->show();
149 | AddItem("悉尼","14°~23°","://res/type/Qing.png");
150 | AddItem("墨尔本","13°~25°","://res/type/Yin.png");
151 | AddItem("布里斯班","14°~23°","://res/type/Qing.png");
152 | AddItem("珀斯","7°~20°","://res/type/Qing.png");
153 | AddItem("克赖斯特彻奇","18°~23°","://res/type/Yu.png");
154 | AddItem("奥克兰","13°~17°","://res/type/Yin.png");
155 | AddItem("惠灵顿","9°~18°","://res/type/Qing.png");
156 | AddItem("皇后镇","1°~9°","://res/type/Yu.png");
157 | AddItem("堪培拉","7°~21°","://res/type/Yin.png");
158 | AddItem("哈密尔顿","9°~17°","://res/type/Yin.png");
159 | }
160 |
161 | //创建自定义的QWidget并和QListWidget的Item关联起来
162 | void WorldListWea::AddItem(QString city, QString temp,QString pic)
163 | {
164 | if(city == updateCity){
165 | //将已获取数据的放入list中
166 | cityList.append(updateCity);
167 | tempList.append(updateTemp);
168 | typeList.append(updateType);
169 | //更新数据
170 | city = updateCity;
171 | temp = updateTemp;
172 | pic = updateType;
173 | cityWithTemp* pItemWidget = new cityWithTemp(this); //新建widget对象
174 | pItemWidget->SetData(city, temp, pic); //设置要写入的城市和天气
175 |
176 | QListWidgetItem* pItem = new QListWidgetItem(); //新建listwidget的一个item
177 | pItem->setData(Qt::UserRole,city); //保存城市数据
178 |
179 | pItem->setSizeHint(QSize(30, 55)); //设置一项的大小
180 | ui->listWidget->addItem(pItem); //加入listwidget
181 | ui->listWidget->setItemWidget(pItem, pItemWidget); //将新建的widget加入到item中
182 | }
183 | else{
184 | //遍历数据,若已存在,直接更新数据
185 | for (auto iCity = cityList.begin(),iTemp = tempList.begin(),iPic = typeList.begin();
186 | iCity != cityList.end(),iTemp != tempList.end(),iPic != typeList.end();
187 | ++iCity,++iTemp,++iPic){
188 | if(city == *iCity){
189 | city = *iCity;
190 | temp = *iTemp;
191 | pic = *iPic;
192 | // qDebug() << *iCity << *iTemp << *iPic;
193 | }
194 | }
195 | cityWithTemp* pItemWidget = new cityWithTemp(this);
196 | pItemWidget->SetData(city, temp, pic);
197 | QListWidgetItem* pItem = new QListWidgetItem();
198 | pItem->setData(Qt::UserRole,city);
199 | pItem->setSizeHint(QSize(30, 55));
200 | ui->listWidget->addItem(pItem);
201 | ui->listWidget->setItemWidget(pItem, pItemWidget);
202 | }
203 | }
204 |
205 | void WorldListWea::on_stateWidget_itemDoubleClicked()
206 | {
207 | QString state = ui->stateWidget->currentItem()->text();
208 | ui->stateWidget->hide();
209 | if(state == "欧洲"){
210 | euCity();
211 | }else if(state == "非洲"){
212 | afCity();
213 | }else if(state == "美洲"){
214 | naCity();
215 | }else if(state == "大洋洲"){
216 | oaCity();
217 | }else{
218 | asiaCity();
219 | }
220 | }
221 |
222 | //回到默认选择大洲状态
223 | void WorldListWea::on_listBtn_clicked()
224 | {
225 | ui->listWidget->hide();
226 | ui->stateWidget->show();
227 | }
228 |
229 | void WorldListWea::getTemp(QString city,QString temp,QString type)
230 | {
231 | updateCity = city;
232 | updateTemp = temp;
233 | updateType = type;
234 | }
235 |
236 | //当列表中项目被双击时
237 | void WorldListWea::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
238 | {
239 | QString cityData = item->data(Qt::UserRole).toString();
240 | emit setData(cityData);
241 | // qDebug() << cityData;
242 | // qDebug() << cityName;
243 | on_listBtn_clicked();
244 | }
245 |
246 | void WorldListWea::on_pushButton_2_clicked()
247 | {
248 | emit setData(ui->pushButton_2->text());
249 | }
250 |
--------------------------------------------------------------------------------
/worldlistwea.h:
--------------------------------------------------------------------------------
1 | #ifndef WORLDLISTWEA_H
2 | #define WORLDLISTWEA_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include "citywithtemp.h"
12 |
13 | namespace Ui {
14 | class WorldListWea;
15 | }
16 |
17 | class WorldListWea : public QMainWindow
18 | {
19 | Q_OBJECT
20 |
21 | public:
22 | explicit WorldListWea(QWidget *parent = nullptr);
23 | ~WorldListWea();
24 | QString updateCity;
25 | QString updateTemp;
26 | QString updateType;
27 | QList cityList;
28 | QList tempList;
29 | QList typeList;
30 | QList clickedCity;
31 |
32 | protected:
33 | void contextMenuEvent(QContextMenuEvent* event);
34 | void mousePressEvent(QMouseEvent* event);
35 | void mouseMoveEvent(QMouseEvent* event);
36 | void setState();
37 | void asiaCity();
38 | void euCity();
39 | void afCity();
40 | void naCity();
41 | void oaCity();
42 |
43 | signals:
44 | void BackButton();
45 | void setData(QString text);
46 | void sendIsland(QString);
47 |
48 | private slots:
49 | void on_pushButton_2_clicked();
50 | void on_listWidget_itemDoubleClicked(QListWidgetItem *item);
51 | void on_stateWidget_itemDoubleClicked();
52 | void on_listBtn_clicked();
53 | void getTemp(QString temp,QString city,QString type);
54 |
55 | private:
56 | Ui::WorldListWea *ui;
57 | QMenu* mExitMenu; // 退出菜单
58 | QAction* mExitAct; // 菜单项(退出)
59 | QPoint mOffset; //窗口移动时,鼠标与左上角的偏移
60 | QNetworkAccessManager* mNetAccessManager;
61 | void AddItem(QString city, QString temp, QString pic);
62 | };
63 |
64 | #endif // WORLDLISTWEA_H
65 |
--------------------------------------------------------------------------------
/worldlistwea.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | WorldListWea
4 |
5 |
6 |
7 | 0
8 | 0
9 | 790
10 | 440
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | -10
21 | 0
22 | 800
23 | 445
24 |
25 |
26 |
27 | QWidget#widget{
28 | border-image: url(:/res/bg.jpg);
29 | }
30 |
31 |
32 |
33 |
34 | 150
35 | 0
36 | 141
37 | 81
38 |
39 |
40 |
41 | -
42 |
43 |
44 | border:none;
45 | background:transparent;
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | 13
58 | 25
59 | 783
60 | 391
61 |
62 |
63 |
64 |
65 | QListView
66 | {
67 | show-decoration-selected: 1;
68 | }
69 |
70 |
71 | QListView::item:selected
72 | {
73 | border: 1px solid #6a6ea9;
74 | }
75 |
76 | QListView::item:selected:!active
77 | {
78 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
79 | stop: 0 #ABAFE5, stop: 1 #8588B2);
80 | }
81 |
82 | QListView::item:selected:active
83 | {
84 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
85 | stop: 0 #6a6ea9, stop: 1 #888dd9);
86 | border-left: 3px solid black;
87 | }
88 |
89 | QListView::item:hover
90 | {
91 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
92 | stop: 0 #FAFBFE, stop: 1 #DCDEF1);
93 | border-left: 3px solid rgb(130, 130, 130);
94 | }
95 |
96 |
97 |
98 |
99 |
100 |
101 | 13
102 | 25
103 | 783
104 | 390
105 |
106 |
107 |
108 | QListView::item {
109 | height: 70px;
110 | }
111 | QListView {
112 | border: 10px solid white;
113 | border-radius: 10px;
114 | }
115 |
116 | QListView::item:selected
117 | {
118 | margin-left: 5px;
119 | border-left: 3px solid black;
120 | }
121 |
122 | QListView::item:selected:!active
123 | {
124 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
125 | stop: 0 #ABAFE5, stop: 1 #8588B2);
126 | }
127 |
128 | QListView::item:selected:active
129 | {
130 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
131 | stop: 0 #6a6ea9, stop: 1 #888dd9);
132 | }
133 |
134 | QListView::item:hover
135 | {
136 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
137 | stop: 0 #FAFBFE, stop: 1 #DCDEF1);
138 | margin-left: 5px;
139 | border-left: 3px solid black;
140 | }
141 |
142 |
143 |
144 |
145 |
146 |
147 | 49
148 | 5
149 | 28
150 | 24
151 |
152 |
153 |
154 | background-color: rgba(0, 0, 0,1);
155 |
156 |
157 |
158 |
159 |
160 |
161 | :/res/list.png:/res/list.png
162 |
163 |
164 |
165 |
166 |
167 | 15
168 | 5
169 | 28
170 | 24
171 |
172 |
173 |
174 | background-color: rgba(0, 0, 0,1);
175 |
176 |
177 |
178 |
179 |
180 |
181 | :/res/back.png:/res/back.png
182 |
183 |
184 |
185 |
186 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
--------------------------------------------------------------------------------