62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
#pragma execution_character_set("utf-8")
|
|
|
|
#include "QWaiting.h"
|
|
#include <QMovie>
|
|
#include <qlabel.h>
|
|
#include <QVBoxLayout>
|
|
#include <QApplication>
|
|
|
|
QWaitingDialog::QWaitingDialog(QWidget* parent, QString msg)
|
|
: QDialog(parent)
|
|
, m_Move(nullptr),
|
|
labelmsg(nullptr)
|
|
{
|
|
|
|
//设置透明度
|
|
//this->setWindowOpacity(0.9);
|
|
this->setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
//取消对话框标题
|
|
setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);//设置为对话框风格,并且去掉边框
|
|
setWindowModality(Qt::WindowModal);//设置为模式对话框,同时在构造该对话框时要设置父窗口
|
|
auto label = new QLabel(this);
|
|
labelmsg = new QLabel(this);
|
|
labelmsg->setText(msg);
|
|
QVBoxLayout* vlayout = new QVBoxLayout(this);
|
|
//label->setMaximumWidth(40);
|
|
vlayout->addWidget(label, 0, Qt::AlignCenter);
|
|
vlayout->addWidget(labelmsg, 0, Qt::AlignCenter);
|
|
this->setLayout(vlayout);
|
|
label->setStyleSheet("background-color: transparent;");
|
|
m_Move = new QMovie(":/loading.gif");
|
|
label->setMovie(m_Move);
|
|
//label->setScaledContents(true);
|
|
m_Move->start();
|
|
}
|
|
void QWaitingDialog::changeMessage(QString msg)
|
|
{
|
|
labelmsg->setText(msg);
|
|
}
|
|
|
|
|
|
QWaitingDialog::~QWaitingDialog()
|
|
{
|
|
m_Move->stop();
|
|
|
|
}
|
|
QWaiting::QWaiting(QWidget* parent, QString msg) :QObject(parent) {
|
|
//QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
_dialog = new QWaitingDialog(parent, msg);
|
|
_dialog->show();
|
|
|
|
//QApplication::restoreOverrideCursor();
|
|
}
|
|
QWaiting::~QWaiting() {
|
|
_dialog->close();
|
|
}
|
|
void QWaiting::changeMessage(QString msg)
|
|
{
|
|
_dialog->changeMessage(msg);
|
|
QApplication::processEvents(QEventLoop::AllEvents);
|
|
}
|