Qt actual combat: Yunxi calendar

Qt actual combat: Yunxi calendar

preface

`

Since the State Council issued the notice on promoting the development plan of Inclusive Finance (2016-2020), the people's governments of all provinces, autonomous regions and municipalities directly under the central government, ministries and commissions directly under the State Council have responded positively and seriously implemented it. The development of Inclusive Finance has entered a climax stage. Major Internet companies and colleges and universities have closely followed the trend of the times and launched various innovative products and software, which is used as a tool to cultivate interest, For the purpose of improving the programming ability of students' software projects, a practical software is created. Relying on the calendar, it has created many relevant special effects, beautiful interface, weather query, schedule management and other practical functions, and the interface meets the aesthetic needs of current teenagers. It is a calendar software that closely follows the trend

1, Renderings of Yunxi calendar

1. Return to today:

As shown in Figure 1, when you click the left and right to query the date, and click return to today, it will automatically return to the current date and change the background color to blue.

2. Weather query:

As shown in Figure 2, click the query button to enter the city to be queried, and click the get weather button to display the weather conditions of the city to be queried

3. Weather refresh:

This function is mainly used to refresh the main interface. Due to network problems, the weather cannot be displayed in time, as shown in Figure 3. Click refresh to solve this problem.

4. Schedule management:

Double click the time of the schedule to be established, and a schedule editing box will pop up, as shown in Figure 4. After entering the schedule to be established, click the plus sign in the main interface to display the current schedule. Of course, if you want to delete it, click the minus sign. The specific operation process is as follows:

5. Double click special effects:

In all interfaces, double-click the mouse to see the relevant special effects, as shown in Figure 5

6. About functions:

Click the about button on the main interface to see the relevant introduction of the software. At the same time, scan the QR code and you can also see a brief introduction to the relevant functions and purposes of the software. As shown in Figure 6 and Figure 7

2, 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: Siyuan bold CN; font-size:28px;");
    ui->textBrowser->setText("          YXCalendar It is a beautiful interface, comprehensive functions and strong portability. It can be used as an accessory plug-in of a platform or large software. It not only provides a login system for managing user information, but also adds double-click special effects for fun and viewing, as well as schedule management. It can manage and optimize the current journey of users. The interface is beautiful, the functions are practical, and the auxiliary functions are rich enough. It is a software worthy of use.");
    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 button background color
                         "border-radius:25px;"//Set fillet radius
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999; "/ / set the background color when the button is clicked
                                              "}");

}
//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, and the global position of the mouse
    QPoint x =y-this->z;
    this->move(x);
}

void Calendar_About::mousePressEvent(QMouseEvent *event)
{
    QWidget::mousePressEvent(event);

    QPoint y =event->globalPos(); //The global position of the mouse relative to the upper left corner of the desktop
    QPoint x =this->geometry().topLeft();   //The position of the upper left corner of the window relative to the desktop
    this-> z =y-x ;//Constant value
}

void Calendar_About::mouseReleaseEvent(QMouseEvent *event)
{
    QWidget::mouseReleaseEvent(event);
    this->z=QPoint();
}

//Mouse double click effect
void Calendar_About::mouseDoubleClickEvent(QMouseEvent *event)
{
    //Determine 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 image
        //Set label to automatically adapt to 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);
        //Make the center of the label in the current double-click position of the mouse
        label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
        //Start playing gif
        movie->start();

        label->show();

        //Bind the signal of QMovie and judge the number of gif playback
        connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
            if (frameNumber == movie->frameCount() - 1)//gif playback times is 1, turn off the label
                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 window title
    setWindowTitle("Yunxi calendar");
    //Set software icon
    setWindowIcon(QIcon("CalenderLogo.ico"));
    this->setWindowIcon(QIcon(":images//CalenderLogo.png"));
    //Form 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 day     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);  //Create a new QNetworkAccessManager object
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));//Correlation signal and slot
    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 row header
    ui->calendarWidget->setNavigationBarVisible(false);
    //QDate date=QDate::currentDate();

    //show grid
    ui->calendarWidget->setGridVisible(true);

    //Remove list header
    ui->calendarWidget->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);

    //ui->calendarWidget->setMinimumDate(date);


    //Double click 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("window minimizing",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){ //Close 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();
}


//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, and the global position of the mouse
    QPoint x =y-this->z;
    this->move(x);
}

void Calendar_Main::mousePressEvent(QMouseEvent *event)
{
    QWidget::mousePressEvent(event);

    QPoint y =event->globalPos(); //The global position of the mouse relative to the upper left corner of the desktop
    QPoint x =this->geometry().topLeft();   //The position of the upper left corner of the window relative to the desktop
    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 button background color
                         "border-radius:20px;"//Set 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 button background color
                         "border-radius:15px;"//Set 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 button background color
                         "border-radius:15px;"//Set 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 button background color
                         "border-radius:15px;"//Set 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 button background color
                         "border-radius:15px;"//Set 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 button background color
                         "border-radius:15px;"//Set 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 button background color
                         "border-radius:15px;"//Set 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 button background color
                        "border-radius:25px;"//Set 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 button background color
                         "border-radius:25px;"//Set 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");  // Gets the value corresponding to the specified key
            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 get network request*/
    manager->get(quest);
}

//Mouse double click effect
void Calendar_Main::mouseDoubleClickEvent(QMouseEvent *event)
{
    //Determine 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 image
        //Set label to automatically adapt to 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);
        //Make the center of the label in the current double-click position of the mouse
        label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
        //Start playing gif
        movie->start();

        label->show();

        //Bind the signal of QMovie and judge the number of gif playback
        connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
            if (frameNumber == movie->frameCount() - 1)//gif playback times is 1, turn off the label
                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 button background color
                         "border-radius:15px;"//Set 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 button background color
                         "border-radius:15px;"//Set 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);

}

//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, and the global position of the mouse
    QPoint x =y-this->z;
    this->move(x);
}

void Calendar_Text::mousePressEvent(QMouseEvent *event)
{
    QWidget::mousePressEvent(event);

    QPoint y =event->globalPos(); //The global position of the mouse relative to the upper left corner of the desktop
    QPoint x =this->geometry().topLeft();   //The position of the upper left corner of the window relative to the desktop
    this-> z =y-x ;//Constant value
}

void Calendar_Text::mouseReleaseEvent(QMouseEvent *event)
{
    QWidget::mouseReleaseEvent(event);
    this->z=QPoint();
}

//Mouse double click effect
void Calendar_Text::mouseDoubleClickEvent(QMouseEvent *event)
{
    //Determine 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 image
        //Set label to automatically adapt to 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);
        //Make the center of the label in the current double-click position of the mouse
        label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
        //gif start playing
        movie->start();

        label->show();

        //Bind the signal of QMovie and judge the number of gif playback
        connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
            if (frameNumber == movie->frameCount() - 1)//gif playback times is 1, turn off the label
                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);  //Create a new QNetworkAccessManager object
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));//Correlation signal and slot
    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");  // Gets the value corresponding to the specified key
            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 get network request*/
    manager->get(quest);
}

void Calendar_Weather::PushBtn()
{
    //Exit button
    ui->pushButton_2->setStyleSheet(
                         //Normal state style
                         "QPushButton{"
                         "background-color:#ffffff; "/ / set button background color
                         "border-radius:25px;"//Set 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 button background color
                         "color:white;"
                         "border-radius:20px;"//Set fillet radius
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#d3d3d3; "/ / set the background color when the button is clicked
                                              "color:black;"
                                              "}");
}

//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, and the global position of the mouse
    QPoint x =y-this->z;
    this->move(x);
}

void Calendar_Weather::mousePressEvent(QMouseEvent *event)
{
    QWidget::mousePressEvent(event);

    QPoint y =event->globalPos(); //The global position of the mouse relative to the upper left corner of the desktop
    QPoint x =this->geometry().topLeft();   //The position of the upper left corner of the window relative to the desktop
    this-> z =y-x ;//Constant value
}

void Calendar_Weather::mouseReleaseEvent(QMouseEvent *event)
{
    QWidget::mouseReleaseEvent(event);
    this->z=QPoint();
}

//Mouse double click effect
void Calendar_Weather::mouseDoubleClickEvent(QMouseEvent *event)
{
    //Determine 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 image
        //Set label to automatically adapt to 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);
        //Make the center of the label in the current double-click position of the mouse
        label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
        //Start playing gif
        movie->start();

        label->show();

        //Bind the signal of QMovie and judge the number of gif playback
        connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
            if (frameNumber == movie->frameCount() - 1)//gif playback times is 1, turn off the label
                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. . Part H

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); //Mouse double click event

private:
    Ui::Calendar_About *ui;

    void PushBtn();


    //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; //minimize
    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); //Mouse double click event

private:
    Ui::Calendar_Main *ui;
    QLabel *bglabel;  //Change the background
    void PushBtn();  //Beautification of controls
    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();

    //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); //Mouse double click event

private:
    Ui::Calendar_Text *ui;
    QFile file;

    //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();

    //Form can be dragged
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    QPoint z;

protected:
    void mouseDoubleClickEvent(QMouseEvent *event); //Mouse double click event

};

#endif // CALENDAR_WEATHER_H


summary

The above is the relevant introduction and code of Yunxi calendar.
Full code download address:
https://download.csdn.net/download/m0_54754302/85160700

You can also take a look at the WeChat official account "Yun Xi Zhi Zai" below, and reply to the "cloud Xi calendar", so that you can get the complete source generation, executable program and related documentation free of charge.

Tags: C++ Qt

Posted by elibizif on Sun, 17 Apr 2022 13:09:09 +0930