当前位置:网站首页>QT actual combat: Yunxi calendar
QT actual combat: Yunxi calendar
2022-04-23 14:27:00 【Spiritual health】
Qt actual combat : Yunxi calendar
List of articles
Preface
Issued by the State Council 《 Promote inclusive financial development plan (2016—2020 year )》 Since notification , The provinces 、 Autonomous region 、 Municipal people's government 、 All ministries, commissions and institutions directly under the State Council responded positively , Seriously implement , The development of Inclusive Finance has entered a climax , Major Internet companies and universities keep up with the trend of the times , Launched a variety of innovative products and software , The software is used as a tool to cultivate interest , The purpose is to improve students' programming ability of software project , Created a practical software , Based on the calendar , Created many related special effects , Beautiful interface and weather query 、 Practical functions such as schedule management , And the interface meets the aesthetic needs of current teenagers , It is a calendar software that keeps up with the trend
One 、 Renderings of Yunxi calendar
1. Back to today :
Pictured 1, When you click left and right to query the date , Click back after today , Will automatically return to the current date , And change the background color to blue .
2. Weather query :
Pictured 2, After clicking the query button , You can enter the city you want to query , Click the get weather button , You can display the weather conditions of the city you want to query
3. Weather refresh :
This function is mainly used to refresh the main interface due to network problems , And can't show the weather in time , Pictured 3, Click refresh , To solve the problem .
4. Schedule management :
Double click the time when you want to create the schedule , A schedule edit box will pop up , Pictured 4 Shown , After entering the schedule to be established , Click the plus sign on the main interface , The current schedule can be displayed , Of course , To delete , Click the minus sign . The specific operation process is as follows :
5. Double click the mouse effect :
In all interfaces , Mouse click , You can see the relevant special effects , Pictured 5
6. About function :
Click the about button on the main interface , You can see the relevant introduction of this software . meanwhile , Scan QR code , You can also see a brief introduction to the relevant functions and purposes of the software . Pictured 6 Sum graph 7
Two 、 Related source code
Project framework :
1. .cpp part
calendar_about:
#include "calendar_about.h"
#include "ui_calendar_about.h"
Calendar_About::Calendar_About(QWidget *parent) :
QWidget(parent),
ui(new Ui::Calendar_About)
{
ui->setupUi(this);
this->move(470,250);
QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect;
opacityEffect->setOpacity(0.7);
ui->label->setGraphicsEffect(opacityEffect);
setWindowTitle(" Yunxi calendar ");
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint |Qt::WindowShadeButtonHint);
this->setWindowIcon(QIcon(":images//CalenderLogo.png"));
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect;
shadow->setOffset(0,0);
shadow->setColor(QColor("#000000"));
shadow->setBlurRadius(30);
ui->textBrowser->setStyleSheet("background-color:rgba(0,0,0,0);color: rgb(255, 255, 255);font-family: Ses blackbody CN; font-size:28px;");
ui->textBrowser->setText(" YXCalendar It is a beautiful interface , Comprehensive function , Portability is strong , It can be used as an accessory plug-in of a certain platform or large software . It not only provides a login system , Used to manage user information , It also adds double-click effects , For fun and viewing , And schedule management , It can manage and optimize the current trip of users , Beautiful interface , Functional and practical , And the auxiliary functions are rich enough , Is a software worth using .");
ui->textBrowser->setGraphicsEffect(shadow);
ui->textBrowser->setContentsMargins(1,1,1,1);
connect(ui->pushButton, &QPushButton::clicked,this, &Calendar_About::close);
PushBtn();
// Form rounding
QBitmap bmp(this->size());
bmp.fill();
QPainter p(&bmp);
p.setPen(Qt::NoPen);
p.setBrush(Qt::black);
p.drawRoundedRect(bmp.rect(),20,20);
setMask(bmp);
}
Calendar_About::~Calendar_About()
{
delete ui;
}
void Calendar_About::PushBtn()
{
// Exit button
ui->pushButton->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:25px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"}");
}
// The form can be dragged
void Calendar_About::mouseMoveEvent(QMouseEvent *event)
{
QWidget::mouseMoveEvent(event);
QPoint y =event->globalPos(); // The position of the mouse relative to the upper left corner of the desktop , Global mouse position
QPoint x =y-this->z;
this->move(x);
}
void Calendar_About::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
QPoint y =event->globalPos(); // The mouse is relative to the upper left corner of the desktop , Global mouse position
QPoint x =this->geometry().topLeft(); // The position of the upper left corner of the window relative to the desktop , window position
this-> z =y-x ;// Constant value
}
void Calendar_About::mouseReleaseEvent(QMouseEvent *event)
{
QWidget::mouseReleaseEvent(event);
this->z=QPoint();
}
// Double click the mouse effect
void Calendar_About::mouseDoubleClickEvent(QMouseEvent *event)
{
// Judge whether it is double clicking with the left mouse button
if(event->button() == Qt::LeftButton)
{
QLabel * label = new QLabel(this);
QMovie * movie = new QMovie("://images/mouse.gif");// load gif picture
// Set up label Automatic adaptation gif Size
label->setScaledContents(true);
label->setMovie(movie);
label->resize(180,180);
label->setStyleSheet("background-color:rgba(0,0,0,0);");
// Set mouse penetration
label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
// Give Way label The center of the is at the double click position of the current mouse
label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
// Start playing gif
movie->start();
label->show();
// binding QMovie The signal of , Judge gif plays
connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
if (frameNumber == movie->frameCount() - 1)//gif The number of plays is 1, Turn off the tag
label->close();
});
}
}
calendar_main
#include "calendar_main.h"
#include "ui_calendar_main.h"
Calendar_Main::Calendar_Main(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Calendar_Main)
{
ui->setupUi(this);
// Set the window title
setWindowTitle(" Yunxi calendar ");
// Set software icon
setWindowIcon(QIcon("CalenderLogo.ico"));
this->setWindowIcon(QIcon(":images//CalenderLogo.png"));
// Window style
setWindowOpacity(0.85);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint |Qt::WindowShadeButtonHint);
move(400,180);
// close button
connect(ui->pushButton, &QPushButton::clicked,this, &Calendar_Main::close);
// Electronic clock and time display
on_lcdNumber_overflow();
QTimer *pTimer=new QTimer();
connect(pTimer,SIGNAL(timeout()),this,SLOT(on_lcdNumber_overflow()));
pTimer->start(500);
QDateTime date = QDateTime::currentDateTime();
ui->DateLabel->setText(date.toString("yyyy year MM month dd Japan ddd"));
// Schedule style
bglabel=ui->label_2;
bglabel->setPixmap(QPixmap(":images//DateText.png"));
bglabel->setScaledContents(true);
ui->textEdit->setStyleSheet("background-color:rgba(0,0,0,0);");
manager = new QNetworkAccessManager(this); // newly build QNetworkAccessManager object
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));// Correlating signals and slots
ui->lineEdit->setStyleSheet("background-color:rgba(0,0,0,0);");
// team introduction
QLabel *TeamLabel=ui->TeamLabel;
TeamLabel->setPixmap(QPixmap(":images//Team.png"));
TeamLabel->setScaledContents(true);
ui->TeamLabel->setStyleSheet("background-color:rgba(0,0,0,0);");
// Control optimization
PushBtn();
// Remove the row header
ui->calendarWidget->setNavigationBarVisible(false);
//QDate date=QDate::currentDate();
// Show grid
ui->calendarWidget->setGridVisible(true);
// Remove the list header
ui->calendarWidget->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
//ui->calendarWidget->setMinimumDate(date);
// Double-click the event
connect(ui->calendarWidget,SIGNAL(activated(const QDate &)),this,SLOT(double1()));
// Tray
tray();
initControl();
// Form rounding
QBitmap bmp(this->size());
bmp.fill();
QPainter p(&bmp);
p.setPen(Qt::NoPen);
p.setBrush(Qt::black);
p.drawRoundedRect(bmp.rect(),20,20);
setMask(bmp);
}
Calendar_Main::~Calendar_Main()
{
delete ui;
}
void Calendar_Main::initTopWidget() // Implementation of switching months
{
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(clickLeft()));
connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(clickRight()));
setLabelText(ui->calendarWidget->selectedDate().year(),ui->calendarWidget->selectedDate().month());
connect(ui->calendarWidget,SIGNAL(currentPageChanged(int,int)),this,SLOT(setLabelText2()));
//setLabelText2();
}
void Calendar_Main::initControl() //
{
QTextCharFormat format;
format.setForeground(QColor(51, 51, 51));
format.setBackground(QColor(247,247,247));
format.setFontFamily("Microsoft YaHei");
format.setFontPointSize(9);
format.setFontWeight(QFont::Medium);
ui->calendarWidget->setHeaderTextFormat(format);
ui->calendarWidget->setWeekdayTextFormat(Qt::Saturday, format);
ui->calendarWidget->setWeekdayTextFormat(Qt::Sunday, format);
initTopWidget();
}
void Calendar_Main::setLabelText(int a, int b)
{
QString m=QString("%1 year %2 month ").arg(a).arg(b);
ui->label_3->setText(m);
}
void Calendar_Main::clickLeft()
{
ui->calendarWidget->showPreviousMonth();
}
void Calendar_Main::clickRight()
{
ui->calendarWidget->showNextMonth();
}
void Calendar_Main::double1()
{
Calendar_Text *text=new Calendar_Text;
text->show();
}
void Calendar_Main::setLabelText2()
{
QString m=QString("%1 year %2 month ").arg(ui->calendarWidget->yearShown()).arg(ui->calendarWidget->monthShown());
ui->label_3->setText(m);
}
void Calendar_Main::selectedDateChanged()
{
currentDateEdit->setDate(ui->calendarWidget->selectedDate());
}
// Electronic clock
void Calendar_Main::on_lcdNumber_overflow()
{
QDateTime date_t=QDateTime::currentDateTime();
this->ui->lcdNumber->setSegmentStyle(QLCDNumber::Flat);
this->ui->lcdNumber->setStyleSheet("color:black;");
this->ui->lcdNumber->display(date_t.toString("HH:mm"));
}
void Calendar_Main::on_UniverseBtn_clicked()
{
QDate date=QDate::currentDate();
ui->calendarWidget->showToday();
ui->calendarWidget->setMinimumDate(date);
}
// Tray
void Calendar_Main::tray()
{
// Tray
menu = new QMenu(this);
menu->setStyleSheet("background-color:rgba(255,255,255);");
QIcon icon(":images//CalenderLogo.png");
SysIcon = new QSystemTrayIcon(this);
SysIcon->setIcon(icon);
SysIcon->setToolTip("YHCalender");
min = new QAction(" Minimize the window ",this);
connect(min,&QAction::triggered,this,&Calendar_Main::hide);
max = new QAction(" window maximizing ",this);
connect(max,&QAction::triggered,this,&Calendar_Main::showMaximized);
restor = new QAction(" Restore the original appearance ",this);
connect(restor,&QAction::triggered,this,&Calendar_Main::showNormal);
quit = new QAction(" sign out ",this);
// connect(quit,&QAction::triggered,this,&MainWindow::close);
connect(quit,&QAction::triggered,qApp,&QApplication::quit);
connect(SysIcon,&QSystemTrayIcon::activated,this,&Calendar_Main::on_activatedSysTrayIcon);
menu->addAction(min);
menu->addAction(max);
menu->addAction(restor);
menu->addSeparator(); // Division
menu->addAction(quit);
SysIcon->setContextMenu(menu);
SysIcon->show();
close();
}
void Calendar_Main::closeEvent(QCloseEvent * event){
// Closing event
if(SysIcon->isVisible())
{
this->hide();
//SysIcon->showMessage("YXCalendar"," Welcome to Yunxi calendar !");
event->ignore();
}
else {
event->accept();
}
}
void Calendar_Main::on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
{
// Event handling of menu items in the tray
switch (reason) {
case QSystemTrayIcon::Trigger:
SysIcon->showMessage("YXCalendar"," Welcome to Yunxi calendar !");
break;
case QSystemTrayIcon::DoubleClick:
this->show();
break;
default:
break;
}
}
void Calendar_Main::on_pushButton_5_clicked()
{
QFile file("try.txt");
file.open(QIODevice::ReadOnly);
QString m=file.readAll();
ui->textEdit->setText(m);
}
void Calendar_Main::on_pushButton_6_clicked()
{
ui->textEdit->clear();
}
void Calendar_Main::on_AboutBtn_clicked()
{
Calendar_About *about=new Calendar_About;
about->show();
}
void Calendar_Main::on_WeatherAskBtn_clicked()
{
Calendar_Weather *weatherAsk = new Calendar_Weather;
weatherAsk->show();
}
// The form can be dragged
void Calendar_Main::mouseMoveEvent(QMouseEvent *event)
{
QWidget::mouseMoveEvent(event);
QPoint y =event->globalPos(); // The position of the mouse relative to the upper left corner of the desktop , Global mouse position
QPoint x =y-this->z;
this->move(x);
}
void Calendar_Main::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
QPoint y =event->globalPos(); // The mouse is relative to the upper left corner of the desktop , Global mouse position
QPoint x =this->geometry().topLeft(); // The position of the upper left corner of the window relative to the desktop , window position
this-> z =y-x ;// Constant value
}
void Calendar_Main::mouseReleaseEvent(QMouseEvent *event)
{
QWidget::mouseReleaseEvent(event);
this->z=QPoint();
}
void Calendar_Main::PushBtn(){
// Exit button
ui->pushButton->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:20px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"}");
// Galaxy model
ui->UniverseBtn->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:15px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"color:white;"
"}");
// Weather query
ui->WeatherAskBtn->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:15px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"color:white;"
"}");
// Set up
ui->SettingBtn->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:15px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"color:white;"
"}");
// About
ui->AboutBtn->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:15px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"color:white;"
"}");
// Time adjustment on both sides of the calendar
ui->pushButton_2->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:15px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#55aaff;"// Set the background color when the button is clicked
"color:white;"
"}");
ui->pushButton_3->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:15px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#55aaff;"// Set the background color when the button is clicked
"color:white;"
"}");
// Schedule adjustment
ui->pushButton_5->setStyleSheet(
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:25px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"color:white;"
"}");
ui->pushButton_6->setStyleSheet(
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:25px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"color:white;"
"}");
}
void Calendar_Main::replyFinished(QNetworkReply *reply)
{
qDebug()<<"finish!!";
//QTextCodec *codec = QTextCodec::codecForName("utf8");
QString all = reply->readAll();//codec->toUnicode().toLocal8Bit();
//ui->textEdit->setText(all);
QJsonParseError err;
QJsonDocument json_recv = QJsonDocument::fromJson(all.toUtf8(),&err);
qDebug() << err.error;
if(!json_recv.isNull())
{
QJsonObject object = json_recv.object();
if(object.contains("data"))
{
QJsonValue value = object.value("data"); // Get specified key Corresponding value
if(value.isObject())
{
QJsonObject object_data = value.toObject();
if(object_data.contains("forecast"))
{
QJsonValue value = object_data.value("forecast");
if(value.isArray())
{
QJsonObject today_weather = value.toArray().at(0).toObject();
weather_type = today_weather.value("type").toString();
QString low = today_weather.value("low").toString();
QString high = today_weather.value("high").toString();
wendu = low.mid(low.length()-3,4) +"~"+ high.mid(high.length()-3,4);
QString strength = today_weather.value("fengli").toString();
strength.remove(0,8);
strength.remove(strength.length()-2,2);
fengli = today_weather.value("fengxiang").toString() + strength;
ui->type->setText(weather_type);
ui->wendu->setText(wendu);
//ui->fengli->setText(fengli);
}
}
}
}
}else
{
qDebug()<<"json_recv is NULL or is not a object !!";
}
reply->deleteLater();
}
void Calendar_Main::on_SettingBtn_clicked()
{
/* Set send data */
//QString local_city = " taiyuan ";
QString local_city = " taiyuan ";
char quest_array[256]="http://wthrcdn.etouch.cn/weather_mini?city=";
QNetworkRequest quest;
//sprintf(quest_array,"%s%s",quest_array,ui->lineEdit->text().toUtf8().data());
sprintf(quest_array,"%s%s",quest_array,local_city.toUtf8().data());
quest.setUrl(QUrl(quest_array));
quest.setHeader(QNetworkRequest::UserAgentHeader,"RT-Thread ART");
//connect(manager,SIGNAL(finished(QNetworkReply *)),this,SLOT(replyFinished(QNetworkReply*)));
/* send out get Network request */
manager->get(quest);
}
// Double click the mouse effect
void Calendar_Main::mouseDoubleClickEvent(QMouseEvent *event)
{
// Judge whether it is double clicking with the left mouse button
if(event->button() == Qt::LeftButton)
{
QLabel * label = new QLabel(this);
QMovie * movie = new QMovie("://images/mouse.gif");// load gif picture
// Set up label Automatic adaptation gif Size
label->setScaledContents(true);
label->setMovie(movie);
label->resize(180,180);
label->setStyleSheet("background-color:rgba(0,0,0,0);");
// Set mouse penetration
label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
// Give Way label The center of the is at the double click position of the current mouse
label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
// Start playing gif
movie->start();
label->show();
// binding QMovie The signal of , Judge gif plays
connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
if (frameNumber == movie->frameCount() - 1)//gif The number of plays is 1, Turn off the tag
label->close();
});
}
}
calendar_text
#include "calendar_text.h"
#include "ui_calendar_text.h"
Calendar_Text::Calendar_Text(QWidget *parent) :
QWidget(parent),
ui(new Ui::Calendar_Text)
{
ui->setupUi(this);
m=ui->textEdit->toPlainText();
setWindowTitle(" Yunxi calendar ");
this->setWindowIcon(QIcon(":images//CalenderLogo.png"));
ui->pushButton->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:15px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"color:white;"
"}");
ui->pushButton_2->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:15px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"color:white;"
"}");
// Form rounding
QBitmap bmp(this->size());
bmp.fill();
QPainter p(&bmp);
p.setPen(Qt::NoPen);
p.setBrush(Qt::black);
p.drawRoundedRect(bmp.rect(),20,20);
setMask(bmp);
}
Calendar_Text::~Calendar_Text()
{
delete ui;
}
void Calendar_Text::on_pushButton_clicked()
{
QByteArray array=ui->textEdit->toPlainText().toUtf8();
QFile file("try.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
// QTextStream in(&file);
// in<<array<<endl;
file.write(array);
file.close();
this->hide();
}
void Calendar_Text::on_pushButton_2_clicked()
{
QFile file("try.txt");
file.open(QIODevice::ReadOnly);
QByteArray array=file.readAll();
ui->textEdit->setText(array);
}
// The form can be dragged
void Calendar_Text::mouseMoveEvent(QMouseEvent *event)
{
QWidget::mouseMoveEvent(event);
QPoint y =event->globalPos(); // The position of the mouse relative to the upper left corner of the desktop , Global mouse position
QPoint x =y-this->z;
this->move(x);
}
void Calendar_Text::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
QPoint y =event->globalPos(); // The mouse is relative to the upper left corner of the desktop , Global mouse position
QPoint x =this->geometry().topLeft(); // The position of the upper left corner of the window relative to the desktop , window position
this-> z =y-x ;// Constant value
}
void Calendar_Text::mouseReleaseEvent(QMouseEvent *event)
{
QWidget::mouseReleaseEvent(event);
this->z=QPoint();
}
// Double click the mouse effect
void Calendar_Text::mouseDoubleClickEvent(QMouseEvent *event)
{
// Judge whether it is double clicking with the left mouse button
if(event->button() == Qt::LeftButton)
{
QLabel * label = new QLabel(this);
QMovie * movie = new QMovie("://images/mouse.gif");// load gif picture
// Set up label Automatic adaptation gif Size
label->setScaledContents(true);
label->setMovie(movie);
label->resize(180,180);
label->setStyleSheet("background-color:rgba(0,0,0,0);");
// Set mouse penetration
label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
// Give Way label The center of the is at the double click position of the current mouse
label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
// Start playing gif
movie->start();
label->show();
// binding QMovie The signal of , Judge gif plays
connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
if (frameNumber == movie->frameCount() - 1)//gif The number of plays is 1, Turn off the tag
label->close();
});
}
}
calendar_weather
#include "calendar_weather.h"
#include "ui_calendar_weather.h"
Calendar_Weather::Calendar_Weather(QWidget *parent) :
QWidget(parent),
ui(new Ui::Calendar_Weather)
{
ui->setupUi(this);
setWindowTitle(" Yunxi calendar ");
this->setWindowIcon(QIcon(":images//CalenderLogo.png"));
manager = new QNetworkAccessManager(this); // newly build QNetworkAccessManager object
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));// Correlating signals and slots
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint |Qt::WindowShadeButtonHint);
// close button
connect(ui->pushButton_2, &QPushButton::clicked,this, &Calendar_Weather::close);
PushBtn();
// Form rounding
QBitmap bmp(this->size());
bmp.fill();
QPainter p(&bmp);
p.setPen(Qt::NoPen);
p.setBrush(Qt::black);
p.drawRoundedRect(bmp.rect(),20,20);
setMask(bmp);
}
Calendar_Weather::~Calendar_Weather()
{
delete ui;
}
void Calendar_Weather::replyFinished(QNetworkReply *reply)
{
qDebug()<<"finish!!";
//QTextCodec *codec = QTextCodec::codecForName("utf8");
QString all = reply->readAll();//codec->toUnicode().toLocal8Bit();
ui->textEdit->setText(all);
QJsonParseError err;
QJsonDocument json_recv = QJsonDocument::fromJson(all.toUtf8(),&err);
qDebug() << err.error;
if(!json_recv.isNull())
{
QJsonObject object = json_recv.object();
if(object.contains("data"))
{
QJsonValue value = object.value("data"); // Get specified key Corresponding value
if(value.isObject())
{
QJsonObject object_data = value.toObject();
if(object_data.contains("forecast"))
{
QJsonValue value = object_data.value("forecast");
if(value.isArray())
{
QJsonObject today_weather = value.toArray().at(0).toObject();
weather_type = today_weather.value("type").toString();
QString low = today_weather.value("low").toString();
QString high = today_weather.value("high").toString();
wendu = low.mid(low.length()-3,4) +"~"+ high.mid(high.length()-3,4);
QString strength = today_weather.value("fengli").toString();
strength.remove(0,8);
strength.remove(strength.length()-2,2);
fengli = today_weather.value("fengxiang").toString() + strength;
ui->type->setText(weather_type);
ui->wendu->setText(wendu);
ui->fengli->setText(fengli);
}
}
}
}
}else
{
qDebug()<<"json_recv is NULL or is not a object !!";
}
reply->deleteLater();
}
void Calendar_Weather::on_pushButton_clicked()
{
/* Set send data */
//QString local_city = " taiyuan ";
QString local_city = ui->lineEdit->text().trimmed();
char quest_array[256]="http://wthrcdn.etouch.cn/weather_mini?city=";
QNetworkRequest quest;
//sprintf(quest_array,"%s%s",quest_array,ui->lineEdit->text().toUtf8().data());
sprintf(quest_array,"%s%s",quest_array,local_city.toUtf8().data());
quest.setUrl(QUrl(quest_array));
quest.setHeader(QNetworkRequest::UserAgentHeader,"RT-Thread ART");
//connect(manager,SIGNAL(finished(QNetworkReply *)),this,SLOT(replyFinished(QNetworkReply*)));
/* send out get Network request */
manager->get(quest);
}
void Calendar_Weather::PushBtn()
{
// Exit button
ui->pushButton_2->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#ffffff;"// Set the button background color
"border-radius:25px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#999999;"// Set the background color when the button is clicked
"}");
// Query weather button
ui->pushButton->setStyleSheet(
// Normal state style
"QPushButton{"
"background-color:#707070;"// Set the button background color
"color:white;"
"border-radius:20px;"// Set the fillet radius
"}"
"QPushButton:hover{"
"background-color:#d3d3d3;"// Set the background color when the button is clicked
"color:black;"
"}");
}
// The form can be dragged
void Calendar_Weather::mouseMoveEvent(QMouseEvent *event)
{
QWidget::mouseMoveEvent(event);
QPoint y =event->globalPos(); // The position of the mouse relative to the upper left corner of the desktop , Global mouse position
QPoint x =y-this->z;
this->move(x);
}
void Calendar_Weather::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
QPoint y =event->globalPos(); // The mouse is relative to the upper left corner of the desktop , Global mouse position
QPoint x =this->geometry().topLeft(); // The position of the upper left corner of the window relative to the desktop , window position
this-> z =y-x ;// Constant value
}
void Calendar_Weather::mouseReleaseEvent(QMouseEvent *event)
{
QWidget::mouseReleaseEvent(event);
this->z=QPoint();
}
// Double click the mouse effect
void Calendar_Weather::mouseDoubleClickEvent(QMouseEvent *event)
{
// Judge whether it is double clicking with the left mouse button
if(event->button() == Qt::LeftButton)
{
QLabel * label = new QLabel(this);
QMovie * movie = new QMovie("://images/mouse.gif");// load gif picture
// Set up label Automatic adaptation gif Size
label->setScaledContents(true);
label->setMovie(movie);
label->resize(180,180);
label->setStyleSheet("background-color:rgba(0,0,0,0);");
// Set mouse penetration
label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
// Give Way label The center of the is at the double click position of the current mouse
label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
// Start playing gif
movie->start();
label->show();
// binding QMovie The signal of , Judge gif plays
connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
if (frameNumber == movie->frameCount() - 1)//gif The number of plays is 1, Turn off the tag
label->close();
});
}
}
main
#include "calendar_main.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Calendar_Main w;
w.show();
return a.exec();
}
2. .h part
calendar_about
#ifndef CALENDAR_ABOUT_H
#define CALENDAR_ABOUT_H
#include <QWidget>
#include <QMouseEvent>
#include <QIcon>
#include <QMovie>
#include <QGraphicsOpacityEffect>
#include <QGraphicsDropShadowEffect>
#include <QMovie>
#include <QLabel>
#include <QMouseEvent>
#include <QLine>
// Form rounding
#include <QBitmap>
#include <QPainter>
namespace Ui {
class Calendar_About;
}
class Calendar_About : public QWidget
{
Q_OBJECT
public:
explicit Calendar_About(QWidget *parent = 0);
~Calendar_About();
protected:
void mouseDoubleClickEvent(QMouseEvent *event); // Double click event
private:
Ui::Calendar_About *ui;
void PushBtn();
// The form can be dragged
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
QPoint z;
};
#endif // CALENDAR_ABOUT_H
calendar_main
#ifndef CALENDAR_MAIN_H
#define CALENDAR_MAIN_H
#include <QMainWindow>
#include <QTimer>
#include <QMenu>
#include <QDate>
#include <QLabel>
#include <QProcess>
#include <QPushButton>
#include <QHBoxLayout>
#include <QCalendarWidget>
#include <QDateEdit>
#include <QFile>
#include <QTextEdit>
#include <QSystemTrayIcon>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include <QString>
#include <QTextCodec>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QMouseEvent>
#include "calendar_text.h"
#include "calendar_about.h"
#include "calendar_weather.h"
// Form rounding
#include <QBitmap>
#include <QPainter>
#include <QMovie>
#include <QLabel>
#include <QMouseEvent>
#include <QLine>
namespace Ui {
class Calendar_Main;
}
class Calendar_Main : public QMainWindow
{
Q_OBJECT
public:
explicit Calendar_Main(QWidget *parent = 0);
~Calendar_Main();
private:
QSystemTrayIcon *SysIcon;
QAction *min; // To minimize the
QAction *max; // Maximize
QAction *restor; // recovery
QAction *quit; // sign out
QMenu *menu;
void closeEvent(QCloseEvent * event);
private slots:
void on_lcdNumber_overflow();
void on_UniverseBtn_clicked();
void double1();
void initTopWidget();
void clickLeft();
void clickRight();
void selectedDateChanged();
void setLabelText2();
void on_pushButton_5_clicked();
void on_pushButton_6_clicked();
void on_AboutBtn_clicked();
void on_WeatherAskBtn_clicked();
void on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason);
void replyFinished(QNetworkReply *reply);
void on_SettingBtn_clicked();
protected:
void mouseDoubleClickEvent(QMouseEvent *event); // Double click event
private:
Ui::Calendar_Main *ui;
QLabel *bglabel; // Changing background
void PushBtn(); // Control beautification
void tray();
QPushButton *m_leftMonthBtn;
QPushButton *m_rightMonthBtn;
QLabel *m_dataLabel;
QWidget *m_topWidget;
QHBoxLayout *m_hBoxLayout;
QPainter *painter;
QRect rect;
QDate date1;
QDateEdit *currentDateEdit;
void setLabelText(int a,int b);
void setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat format);
void initControl();
// The form can be dragged
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
QPoint z;
QNetworkAccessManager *manager;
QNetworkRequest *quest;
QString fengli;
QString wendu;
QString weather_type;
};
#endif // CALENDAR_MAIN_H
calendar_text
#ifndef CALENDAR_TEXT_H
#define CALENDAR_TEXT_H
#include <QWidget>
#include<QFile>
#include<QString>
#include<QFile>
#include<QTextStream>
// Form rounding
#include <QBitmap>
#include <QPainter>
#include <QMovie>
#include <QLabel>
#include <QMouseEvent>
#include <QLine>
namespace Ui {
class Calendar_Text;
}
class Calendar_Text : public QWidget
{
Q_OBJECT
public:
explicit Calendar_Text(QWidget *parent = 0);
~Calendar_Text();
QString m;
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
protected:
void mouseDoubleClickEvent(QMouseEvent *event); // Double click event
private:
Ui::Calendar_Text *ui;
QFile file;
// The form can be dragged
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
QPoint z;
};
#endif // CALENDAR_TEXT_H
calendar_weather
#ifndef CALENDAR_WEATHER_H
#define CALENDAR_WEATHER_H
#include <QWidget>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include <QString>
#include <QTextCodec>
// Form rounding
#include <QBitmap>
#include <QPainter>
#include <QMovie>
#include <QLabel>
#include <QMouseEvent>
#include <QLine>
namespace Ui {
class Calendar_Weather;
}
class Calendar_Weather : public QWidget
{
Q_OBJECT
public:
explicit Calendar_Weather(QWidget *parent = 0);
~Calendar_Weather();
private slots:
void replyFinished(QNetworkReply *reply);
void on_pushButton_clicked();
private:
Ui::Calendar_Weather *ui;
QNetworkAccessManager *manager;
QNetworkRequest *quest;
QString fengli;
QString wendu;
QString weather_type;
void PushBtn();
// The form can be dragged
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
QPoint z;
protected:
void mouseDoubleClickEvent(QMouseEvent *event); // Double click event
};
#endif // CALENDAR_WEATHER_H
summary
The above is the relevant introduction and code of Yunxi calendar .
CSDN download
https://download.csdn.net/download/m0_54754302/85160700
WeChat official account can also be searched. “ Yunxi Zhihua ”, reply “ Yunxi calendar ”, that will do free Get the complete source code 、 Executable programs and related documentation
版权声明
本文为[Spiritual health]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231411423176.html
边栏推荐
- flannel 原理 之 子网划分
- C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【2】
- Redis源码分析之HSET流程与ziplist
- js 抛物线运动方法封装
- 八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
- JS recursion (1)
- 循环队列的基本操作(实验)
- Introduction to loan market quotation interest rate (LPR) and loan benchmark interest rate
- js 递归(1)
- AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
猜你喜欢
Qt界面优化:Qt去边框与窗体圆角化
51单片机的直流电机PWM调速控制系统(附Proteus仿真+C程序等全套资料)
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
AT89C52单片机的频率计(1HZ~20MHZ)设计,LCD1602显示,含仿真、原理图、PCB与代码等
OpenFaaS实战之四:模板操作(template)
KVM学习资源
Qt实战:云曦日历篇
51单片机的花卉、农田自动浇水灌溉系统开发,Proteus仿真,原理图和C代码
Uni app message push
随机推荐
Introduction to loan market quotation interest rate (LPR) and loan benchmark interest rate
tcp_diag 内核相关实现 1 调用层次
C语言知识点精细详解——初识C语言【1】
redis的五种数据类型
LotusDB 设计与实现—1 基本概念
js 格式化时间
翻牌效果
关于在vs中使用scanf不安全的问题
51单片机+LCD12864液晶显示的俄罗斯方块游戏,Proteus仿真、AD原理图、代码、论文等
顺序栈的基本操作
电子秤称重系统设计,HX711压力传感器,51单片机(Proteus仿真、C程序、原理图、论文等全套资料)
一款不错的工具:aardio
初始c语言大致框架适合复习和初步认识
ansible及常用模块的使用
js 递归(1)
Matrix exchange row and column
Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
KVM learning resources
IE8 browser prompts whether to block access to JS script
async void 导致程序崩溃