Qt实战:云曦Convert篇

简介: Qt实战:云曦Convert篇

Qt实战:云曦Convert篇


前言

云曦Convert软件主要采用C++、Python、Html等语言编写,以Qt5.11.1和Pycharm为编译器,运用DJANGO框架和相关QT模型与算法,以Python为后端,Qt为前端,前后端结合,为用户提供PDF文件合并,选择拆分,平均拆分以及语音导航等功能,实现用户对PDF编辑更加多样化的需求。


一、云曦Convert效果图

1. 回到首页:

在桌面上双击系统的图标就会出现以下的界面,这时候就会弹出了应用首页的界面,从这个界面中可以看到本软件所提供的相关功能和注意事项,如需在连网情况下适用等,如果不连接网络,将无法正常使用该软件,详情如下图1-1所示:

在这里插入图片描述

2. 选择拆分:

点击选择拆分按钮,将所需要拆分的文件拖入提示框中,如图2-1所示,然后输入要拆分的页数范围,点击拆分即可,详情见下图:

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

3. 平均拆分:

具体操作同选择拆分,点击平均拆分按钮,将所需要拆分的文件拖入提示框中,如图2-4所示,然后输入要平均拆分的页数,点击拆分即可,详情见下图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4. 文件合并 :

同上述功能操作,点击文件合并按钮,将所要合并的文件拖入框中,输入合并后的文件名,点击合并,合并后打开即可,如图2-9所示。

在这里插入图片描述

5. 语音助手:

点击界面右上方类似于耳机的按钮,即可召唤出语音助手,来为您讲解我们的项目。如下图所示,该功能详细代码解析点击此处
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

二、相关源代码

项目框架图:
在这里插入图片描述

1. .cpp部分

assistant_1:
#include "assistant_1.h"
#include "ui_assistant_1.h"

Assistant_1::Assistant_1(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Assistant_1)
{
    ui->setupUi(this);
    BeaWindow(); //窗口优化
    BeaBtn(); //按钮优化
}

Assistant_1::~Assistant_1()
{
    delete ui;
}

//点击下一步
void Assistant_1::on_pushButton_clicked()
{
    this->close();
    Assistant_2 *assistant_2 = new Assistant_2();
    assistant_2->show();

    QMediaPlayer * player = new QMediaPlayer;

    player->setMedia(QUrl::fromLocalFile("images/assistantend.mp3"));
    player->setVolume(70);
    player->play();


}

//鼠标双击特效
void Assistant_1::mouseDoubleClickEvent(QMouseEvent *event)
{
    //判断是否为鼠标左键双击
    if(event->button() == Qt::LeftButton)
    {
        QLabel * label = new QLabel(this);
        QMovie * movie = new QMovie("://images/mouse.gif");//加载gif图片
        //设置label自动适应gif的大小
        label->setScaledContents(true);

        label->setMovie(movie);
        //这里为了调用move方便,进行resize,需要知道的是gif的大小本来也就是150*150
        label->resize(180,180);
        //设置鼠标穿透
        label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
        //让label的中心在当前鼠标双击位置
        label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
        //开始播放gif
        movie->start();

        label->show();

        //绑定QMovie的信号,判断gif播放次数
        connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
            if (frameNumber == movie->frameCount() - 1)//gif播放次数为1,关闭标签
                label->close();
        });
    }
}

//窗体美化
void Assistant_1::BeaWindow()
{
    setWindowFlags(Qt::FramelessWindowHint);
    this->setWindowTitle("YXConvert");
    setWindowOpacity(0.85);

    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);
}

//窗口可移动
void Assistant_1::mouseMoveEvent(QMouseEvent *event)
{
    QWidget::mouseMoveEvent(event);

    QPoint y =event->globalPos(); //鼠标相对于桌面左上角的位置,鼠标全局位置
    QPoint x =y-this->z;
    this->move(x);
}

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

    QPoint y =event->globalPos(); //鼠标相对于桌面左上角,鼠标全局位置
    QPoint x =this->geometry().topLeft();   //窗口左上角相对于桌面位置,窗口位置
    this-> z =y-x ;//定值不变
}

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

//按钮美化
void Assistant_1::BeaBtn()
{
    //退出按钮
    connect(ui->exitBtn, &QPushButton::clicked,this, &Assistant_1::close);

    ui->exitBtn->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:35px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "}");
    //下一步
    ui->pushButton->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#B8C8D9;"//设置按钮背景色
                         "border-radius:20px;"//设置圆角半径
                         "color: #ffffff"
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "}");

}

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

    //设置窗口标题
    setWindowTitle("云曦日历");
    //设置软件图标
    setWindowIcon(QIcon("CalenderLogo.ico"));
    this->setWindowIcon(QIcon(":images//CalenderLogo.png"));
    //窗体样式
    setWindowOpacity(0.85);
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint |Qt::WindowShadeButtonHint);
    move(400,180);

    //关闭按钮
    connect(ui->pushButton, &QPushButton::clicked,this, &Calendar_Main::close);


    //电子时钟与时期显示
    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年MM月dd日     ddd"));

    //日程样式
    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);  //新建QNetworkAccessManager对象
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));//关联信号和槽
    ui->lineEdit->setStyleSheet("background-color:rgba(0,0,0,0);");




    //团队介绍
    QLabel *TeamLabel=ui->TeamLabel;
    TeamLabel->setPixmap(QPixmap(":images//Team.png"));
    TeamLabel->setScaledContents(true);
    ui->TeamLabel->setStyleSheet("background-color:rgba(0,0,0,0);");

    //控件优化
    PushBtn();

    //去掉行表头
    ui->calendarWidget->setNavigationBarVisible(false);
    //QDate date=QDate::currentDate();

    //显示网格
    ui->calendarWidget->setGridVisible(true);

    //去掉列表头
    ui->calendarWidget->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);

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


    //双击事件
    connect(ui->calendarWidget,SIGNAL(activated(const QDate &)),this,SLOT(double1()));

    //托盘
    tray();

    initControl();

    //窗体圆角化
    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()  //切换月份的实现
{

    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年%2月").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年%2月").arg(ui->calendarWidget->yearShown()).arg(ui->calendarWidget->monthShown());
    ui->label_3->setText(m);
}

void Calendar_Main::selectedDateChanged()
{
    currentDateEdit->setDate(ui->calendarWidget->selectedDate());
}

//电子时钟
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);


}

//托盘
void Calendar_Main::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("窗口最小化",this);
    connect(min,&QAction::triggered,this,&Calendar_Main::hide);

    max = new QAction("窗口最大化",this);
    connect(max,&QAction::triggered,this,&Calendar_Main::showMaximized);
    restor = new QAction("恢复原来的样子",this);
    connect(restor,&QAction::triggered,this,&Calendar_Main::showNormal);
    quit = new QAction("退出",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(); //分割
    menu->addAction(quit);
    SysIcon->setContextMenu(menu);
    SysIcon->show();
    close();
}
void Calendar_Main::closeEvent(QCloseEvent * event){ //关闭事件
    if(SysIcon->isVisible())
          {
              this->hide();
              //SysIcon->showMessage("YXCalendar","欢迎使用云曦日历!");
              event->ignore();
          }
          else {
              event->accept();
          }

}
void Calendar_Main::on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
{ //对托盘中的菜单项的事件处理
    switch (reason) {

    case QSystemTrayIcon::Trigger:
        SysIcon->showMessage("YXCalendar","欢迎使用云曦日历!");
        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();
}


//窗体可拖动
void Calendar_Main::mouseMoveEvent(QMouseEvent *event)
{
    QWidget::mouseMoveEvent(event);

    QPoint y =event->globalPos(); //鼠标相对于桌面左上角的位置,鼠标全局位置
    QPoint x =y-this->z;
    this->move(x);
}

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

    QPoint y =event->globalPos(); //鼠标相对于桌面左上角,鼠标全局位置
    QPoint x =this->geometry().topLeft();   //窗口左上角相对于桌面位置,窗口位置
    this-> z =y-x ;//定值不变
}

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


void Calendar_Main::PushBtn(){
    //退出按钮
    ui->pushButton->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:20px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "}");
    //星系模型
    ui->UniverseBtn->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:15px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "color:white;"
                                              "}");
    //天气查询
    ui->WeatherAskBtn->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:15px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "color:white;"
                                              "}");
    //设置
    ui->SettingBtn->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:15px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "color:white;"
                                              "}");
    //关于
    ui->AboutBtn->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:15px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "color:white;"
                                              "}");
    //日历两侧的时间调整
    ui->pushButton_2->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:15px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#55aaff;"//设置按钮点击时的背景颜色
                                              "color:white;"
                                              "}");
    ui->pushButton_3->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:15px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#55aaff;"//设置按钮点击时的背景颜色
                                              "color:white;"
                                              "}");
    //日程的调整
    ui->pushButton_5->setStyleSheet(
                        "QPushButton{"
                        "background-color:#ffffff;"//设置按钮背景色
                        "border-radius:25px;"//设置圆角半径
                        "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "color:white;"
                                              "}");
    ui->pushButton_6->setStyleSheet(
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:25px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "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");  // 获取指定 key 对应的 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()
{
    /*设置发送数据*/
    //QString local_city = "太原";
    QString local_city = "太原";
    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*)));
    /*发送get网络请求*/
    manager->get(quest);
}

//鼠标双击特效
void Calendar_Main::mouseDoubleClickEvent(QMouseEvent *event)
{
    //判断是否为鼠标左键双击
    if(event->button() == Qt::LeftButton)
    {
        QLabel * label = new QLabel(this);
        QMovie * movie = new QMovie("://images/mouse.gif");//加载gif图片
        //设置label自动适应gif的大小
        label->setScaledContents(true);

        label->setMovie(movie);

        label->resize(180,180);
        label->setStyleSheet("background-color:rgba(0,0,0,0);");
        //设置鼠标穿透
        label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
        //让label的中心在当前鼠标双击位置
        label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
        //开始播放gif
        movie->start();

        label->show();

        //绑定QMovie的信号,判断gif播放次数
        connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
            if (frameNumber == movie->frameCount() - 1)//gif播放次数为1,关闭标签
                label->close();
        });
    }
}

assistantwidget
#include "assistantwidget.h"
#include "ui_assistantwidget.h"

AssistantWidget::AssistantWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AssistantWidget)
{
    ui->setupUi(this);

    BeaWindow(); //窗口优化
    BeaBtn(); //按钮优化
}

AssistantWidget::~AssistantWidget()
{
    delete ui;
}

//点击进入下一步
void AssistantWidget::on_pushButton_clicked()
{
    this->close();
    Assistant_1 * assistant_1 = new Assistant_1();
    assistant_1->show();
}

//鼠标双击特效
void AssistantWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
    //判断是否为鼠标左键双击
    if(event->button() == Qt::LeftButton)
    {
        QLabel * label = new QLabel(this);
        QMovie * movie = new QMovie("://images/mouse.gif");//加载gif图片
        //设置label自动适应gif的大小
        label->setScaledContents(true);

        label->setMovie(movie);
        //这里为了调用move方便,进行resize,需要知道的是gif的大小本来也就是150*150
        label->resize(180,180);
        //设置鼠标穿透
        label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
        //让label的中心在当前鼠标双击位置
        label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
        //开始播放gif
        movie->start();

        label->show();

        //绑定QMovie的信号,判断gif播放次数
        connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
            if (frameNumber == movie->frameCount() - 1)//gif播放次数为1,关闭标签
                label->close();
        });
    }
}

//窗体美化
void AssistantWidget::BeaWindow()
{
    setWindowFlags(Qt::FramelessWindowHint);
    this->setWindowTitle("YXConvert");
    setWindowOpacity(0.85);

    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);
}

//窗口可移动
void AssistantWidget::mouseMoveEvent(QMouseEvent *event)
{
    QWidget::mouseMoveEvent(event);

    QPoint y =event->globalPos(); //鼠标相对于桌面左上角的位置,鼠标全局位置
    QPoint x =y-this->z;
    this->move(x);
}

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

    QPoint y =event->globalPos(); //鼠标相对于桌面左上角,鼠标全局位置
    QPoint x =this->geometry().topLeft();   //窗口左上角相对于桌面位置,窗口位置
    this-> z =y-x ;//定值不变
}

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

//按钮美化
void AssistantWidget::BeaBtn()
{
    //退出按钮
    connect(ui->exitBtn, &QPushButton::clicked,this, &AssistantWidget::close);

    ui->exitBtn->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#ffffff;"//设置按钮背景色
                         "border-radius:35px;"//设置圆角半径
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "}");
    //下一步
    ui->pushButton->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#B8C8D9;"//设置按钮背景色
                         "border-radius:20px;"//设置圆角半径
                         "color: #ffffff"
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "}");

}

chosplit
#include "chosplit.h"
#include "ui_chosplit.h"

ChoSplit::ChoSplit(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ChoSplit)
{
    ui->setupUi(this);

    this->setAcceptDrops(true);

    BeaWindow(); //窗体美化
    BeaBtn(); //按钮美化
}

ChoSplit::~ChoSplit()
{
    delete ui;
}


//鼠标拖拽事件
void ChoSplit::dragEnterEvent(QDragEnterEvent *event)
{
    QString fileName = event->mimeData()->urls().first().toLocalFile();
    QFileInfo file = QFileInfo(fileName);
    QString file_suffix = file.suffix();
    if(file_suffix == "pdf")
        event->acceptProposedAction();
}

//鼠标拖拽放下事件,返回文件的URL
void ChoSplit::dropEvent(QDropEvent *event)
{
    urlFile = event->mimeData()->urls().first().toString();
    qDebug()<<urlFile;
    ui->dragLabel->close();
    QMessageBox msg(this);
    msg.setWindowTitle("YHConvert");
    msg.setText("拖入成功,文件名及路径为:"+urlFile);
    msg.setIcon(QMessageBox::Information);
    msg.setStandardButtons(QMessageBox::Ok);
    if(msg.exec()==QMessageBox::Ok)
    {
        QFont ft;
        ft.setPointSize(9);
        QPalette label_pe;
        label_pe.setColor(QPalette::WindowText,Qt::black);
        ui->dragLabel->setText(urlFile);
        ui->dragLabel->setFont(ft);
        ui->dragLabel->setPalette(label_pe);
        ui->dragLabel->show();
    }

}

//Json数据解析
void ChoSplit::finishedSlot1(QNetworkReply *reply)
{
    if(this->reply->error()==QNetworkReply::NoError)
    {

        QByteArray  bytes = reply->readAll();
        QJsonDocument doc1=QJsonDocument::fromJson(bytes);
        QJsonObject json=doc1.object();
        doc1.setObject(json);
        QByteArray byte=doc1.toJson();
        QString str=QString(byte);
        qDebug() <<str;

        QJsonParseError err;
        QJsonDocument doc2=QJsonDocument::fromJson(byte,&err);
        QJsonObject json2=doc2.object();
        if(err.error != QJsonParseError::NoError)
        {
            qDebug()<<"json数据格式错误";
        }
        else
        {
            QJsonValue urlValue = json2.value("url");
            urlAlreadySplit=urlValue.toString();
            QString path=urlAlreadySplit.section('/',2);
            qDebug()<<path;
            QMessageBox msg(this);
            msg.setWindowTitle("YHConvert");
            msg.setText("拆分成功,文件名及原始路径为:"+urlFile+"点击打开,可查看拆分结果");
            msg.setIcon(QMessageBox::Information);
            msg.setStandardButtons(QMessageBox::Ok);
            if(msg.exec()==QMessageBox::Ok){}
            //pathAlreadySplit=path;

        }

    }

    else
    {
        qDebug()<<"handle errors here";
        QVariant statusCodeV = this->reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
        //statusCoV是HTTdeP服务器的相应码,reply->error()是Qt定义的错误码,可以参考QT的文档
        qDebug( "found error ....code: %d %d\n", statusCodeV.toInt(), (int)this->reply->error());
        qDebug(qPrintable(this->reply->errorString()));
    }
    this->reply->deleteLater();
}

//选择拆分
void ChoSplit::on_cho_splitBtn_clicked()
{
    m_manage=new QNetworkAccessManager(this);
    connect(m_manage,SIGNAL(finished(QNetworkReply *)),this,SLOT(finishedSlot1(QNetworkReply *)));

    QString  a=ui->begText->toPlainText();
    QString  b=ui->endText->toPlainText();

    QByteArray by1 = a.toUtf8();
    QByteArray by2 = b.toUtf8();

    parPart1.setHeader(QNetworkRequest::ContentDispositionHeader , QVariant(" form-data; name=start_page"));
    parPart1.setBody(by1);

    parPart2.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=end_page"));
    parPart2.setBody(by2);

    QHttpPart dbFilePart;
    dbFilePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=PdfFile; filename=new.pdf")); // file为后端定义的key,filename即为excel文件名

    QUrl url=urlFile;
    QString path=url.toLocalFile();
    qDebug()<<path;

    QFile::setPermissions(path,QFile::WriteOwner|QFile::ReadOwner);//设置读写权限
    multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

    file = new QFile(path);
    file->open(QIODevice::ReadOnly);
    dbFilePart.setBodyDevice(file);
    file->setParent(multiPart);

    multiPart->append(parPart1);
    multiPart->append(parPart2);
    multiPart->append(dbFilePart);

    QNetworkRequest request;
    request.setUrl(QUrl("http://heart.jixiaob.cn/PDF/e_split/"));
    this->reply = this->m_manage->post(request, multiPart);
    multiPart->setParent(reply);

    QMessageBox msg(this);
    msg.setWindowTitle("YHConvert");
    msg.setText("拆分中,请稍等......");
    msg.setIcon(QMessageBox::Information);
    msg.setStandardButtons(QMessageBox::Ok);
    if(msg.exec()==QMessageBox::Ok){}

}

void ChoSplit::on_cho_openBtn_clicked()
{
    QFile file(pathAlreadySplit);
    qDebug()<<pathAlreadySplit;
    file.open(QIODevice::ReadOnly);
    qDebug()<<"nihaoya";
    QDesktopServices::openUrl(QUrl::fromLocalFile(urlAlreadySplit));
}

//鼠标双击特效
void ChoSplit::mouseDoubleClickEvent(QMouseEvent *event)
{
    //判断是否为鼠标左键双击
    if(event->button() == Qt::LeftButton)
    {
        QLabel * label = new QLabel(this);
        QMovie * movie = new QMovie("://images/mouse.gif");//加载gif图片
        //设置label自动适应gif的大小
        label->setScaledContents(true);

        label->setMovie(movie);
        //这里为了调用move方便,进行resize,需要知道的是gif的大小本来也就是150*150
        label->resize(180,180);
        //设置鼠标穿透
        label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
        //让label的中心在当前鼠标双击位置
        label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
        //开始播放gif
        movie->start();

        label->show();

        //绑定QMovie的信号,判断gif播放次数
        connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
            if (frameNumber == movie->frameCount() - 1)//gif播放次数为1,关闭标签
                label->close();
        });
    }
}

//窗体美化
void ChoSplit::BeaWindow()
{
    setWindowFlags(Qt::FramelessWindowHint);
    this->setWindowTitle("YHConvert");

    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);
}


//按钮美化
void ChoSplit::BeaBtn()
{

    //打开
    ui->cho_openBtn->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#B8C8D9;"//设置按钮背景色
                         "border-radius:20px;"//设置圆角半径
                         "color: #ffffff"
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "}");

    //拆分
    ui->cho_splitBtn->setStyleSheet(
                         //正常状态样式
                         "QPushButton{"
                         "background-color:#B8C8D9;"//设置按钮背景色
                         "border-radius:20px;"//设置圆角半径
                         "color: #ffffff"
                         "}"
                         "QPushButton:hover{"
                                              "background-color:#999999;"//设置按钮点击时的背景颜色
                                              "}");


}

2. .h部分

assistant_1:
#ifndef ASSISTANT_1_H
#define ASSISTANT_1_H

#include <QWidget>

#include <QBitmap>
#include <QPainter>

#include <QMouseEvent>
#include <QMovie>
#include <QLabel>

#include <QMediaPlayer>

#include "assistant_2.h"

namespace Ui {
class Assistant_1;
}

class Assistant_1 : public QWidget
{
    Q_OBJECT

public:
    explicit Assistant_1(QWidget *parent = 0);
    ~Assistant_1();

protected:
    void mouseDoubleClickEvent(QMouseEvent *event); //鼠标双击事件

private slots:
    void on_pushButton_clicked();

private:
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    QPoint z;

private:
    Ui::Assistant_1 *ui;
    void BeaWindow(); //窗体优化
    void BeaBtn(); //按钮优化
};

#endif // ASSISTANT_1_H
assistantwidget
#ifndef ASSISTANTWIDGET_H
#define ASSISTANTWIDGET_H

#include <QWidget>

#include <QBitmap>
#include <QPainter>

#include <QMouseEvent>
#include <QMovie>
#include <QLabel>

#include <QMediaPlayer>

#include "assistant_1.h"
namespace Ui {
class AssistantWidget;
}

class AssistantWidget : public QWidget
{
    Q_OBJECT

public:
    explicit AssistantWidget(QWidget *parent = 0);
    ~AssistantWidget();

protected:
    void mouseDoubleClickEvent(QMouseEvent *event); //鼠标双击事件

private slots:
    void on_pushButton_clicked();

private:
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    QPoint z;

private:
    Ui::AssistantWidget *ui;
    void BeaWindow(); //窗体优化
    void BeaBtn(); //按钮优化
};

#endif // ASSISTANTWIDGET_H
chosplit
#ifndef CHOSPLIT_H
#define CHOSPLIT_H

#include <QWidget>

#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QVariant>
#include <QByteArray>
#include <QUrl>
#include <QLineEdit>

#include <QJsonDocument>
#include <QJsonObject>
#include <QHttpPart>
#include <QHttpMultiPart>

#include <QFile>
#include <QDebug>

#include <QDragEnterEvent>
#include <QDropEvent>

#include <QFileInfo>
#include <QMimeData>
#include <QJsonParseError>
#include <QDesktopServices>
#include <QJsonArray>

#include <QBitmap>
#include <QPainter>

#include <QMouseEvent>
#include <QMovie>
#include <QLabel>

#include <QMessageBox>

namespace Ui {
class ChoSplit;
}

class ChoSplit : public QWidget
{
    Q_OBJECT

public:
    explicit ChoSplit(QWidget *parent = 0);
    ~ChoSplit();

protected:
    void mouseDoubleClickEvent(QMouseEvent *event); //鼠标双击事件


private:
    Ui::ChoSplit *ui;

    void dragEnterEvent(QDragEnterEvent *event);
    void dropEvent(QDropEvent *event);

    QNetworkAccessManager *m_manage;
    QNetworkReply* reply;
    QNetworkRequest* m_request;

    QHttpPart parPart1;  //start_page
    QHttpPart parPart2;  //end_page

    QHttpMultiPart *multiPart;

    QFile *file;   //post上传文件

    QString urlFile;  //拖入文件的URL


    QString urlAlreadySplit;   //拆分后文件的URL
    QString pathAlreadySplit;  //拆分后文件的path

    void BeaWindow(); //窗体美化
    void BeaBtn(); //按钮美化

private  slots:
    void finishedSlot1(QNetworkReply *);

    void on_cho_splitBtn_clicked();
    void on_cho_openBtn_clicked();


};

#endif // CHOSPLIT_H

总结一

以上就是云曦日历的相关简介和部分代码,篇幅有限,大家可以直接通过以下方式获取完整代码,相关细节功能与设计均在Qt功能优化Qt界面优化两大专栏中,大家可以也点击下方的总结二中的推荐文章进行跳转和查看。

CSDN下载:
https://download.csdn.net/download/m0_54754302/85203776

微信公众号:
也可搜索关注微信公众号“云曦智划”,回复“云曦Convert”,即可免费获取完整源代、可执行程序以及相关说明文档。

总结二

以上是部分Qt关于实战的部分,所有相关的Qt实战的部分,均在下方专栏——Qt实战中,大家如果感兴趣可以进行观看并使用,希望通过这些文章能够使大家的Qt软件更加美观和完美 !!!

另,如果大家有时间的话,也可以在个人主页中的专栏部分,查看我的Qt界面优化专栏Qt功能优化专栏哦,里面分别存放有Qt相关的实战软件和相对实用的附属功能,大家感兴趣可以看看(๑>؂<๑)

另附Qt界面优化:鼠标双击特效Qt功能优化:Qt链接外部程序两篇相关文章,大家可以下滑到文章下方专栏处,查看相关专栏中的其它文章,希望能帮助到大家,感谢大家支持~( ̄▽ ̄~)~

相关文章
|
1月前
|
存储 搜索推荐 人机交互
Qt鼠标事件全面解析:从基础到实战
Qt鼠标事件全面解析:从基础到实战
120 0
|
1月前
|
监控 安全 Linux
Qt 文件类实战:解锁文件操作的无限可能
Qt 文件类实战:解锁文件操作的无限可能
48 1
|
1月前
|
数据可视化 API vr&ar
探索Qt 3D之旅:从基础到实战,打造引人入胜的三维界面与应用
探索Qt 3D之旅:从基础到实战,打造引人入胜的三维界面与应用
123 2
|
4月前
|
图形学 容器
QT chart图表(温度曲线实战)
QT chart图表(温度曲线实战)
83 0
|
1月前
|
Windows
Qt5.14.2 轻松掌握Qt中的压缩与解压缩:QuaZIP的神秘面纱与实战演练之使用QuaZIP
Qt5.14.2 轻松掌握Qt中的压缩与解压缩:QuaZIP的神秘面纱与实战演练之使用QuaZIP
|
1月前
|
Unix 编译器 开发者
Qt5.14.2 轻松掌握Qt中的压缩与解压缩:QuaZIP的神秘面纱与实战演练之windows环境编译
Qt5.14.2 轻松掌握Qt中的压缩与解压缩:QuaZIP的神秘面纱与实战演练之windows环境编译
|
5月前
|
JSON 搜索推荐 数据库
基于Qt框架实战:MP3音乐播放器搜索引擎
基于Qt框架实战:MP3音乐播放器搜索引擎
基于Qt框架实战:MP3音乐播放器搜索引擎
|
7月前
|
算法 C++
|
1月前
|
编解码 开发者 UED
Qt布局实战:实现高效、美观的GUI应用程序
Qt布局实战:实现高效、美观的GUI应用程序
117 2
|
10月前
|
Python
Python Qt GUI设计:做一款串口调试助手(实战篇—1)
Python Qt GUI设计系列博文终于到了实战篇,本篇博文将贯穿之前的基础知识点实现一款串口调试助手。

热门文章

最新文章

推荐镜像

更多