#include #include #include #include #include #include #include ; #include static QPixmap cvMatToQPixmap(const cv::Mat& mat) { QImage qImg; if (mat.channels() == 3) { //cv::cvtColor(mat, mat, cv::COLOR_BGR2RGB); qImg = QImage(mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB888); } else { qImg = QImage((const unsigned char*)(mat.data), mat.cols, mat.rows, mat.step, QImage::Format_Grayscale8); } return QPixmap::fromImage(qImg); } class loadingWidget : public QWidget { public: QLabel* sign; QMovie* movie; QTextEdit* initLog; QGridLayout* glayout = new QGridLayout(this); loadingWidget(QWidget* parent = nullptr) : QWidget(parent) { glayout->setAlignment(Qt::AlignCenter); } void start(QWidget* widget) { QPalette palette; palette.setColor(QPalette::WindowText, Qt::white); sign = new QLabel(this); sign->setAlignment(Qt::AlignBottom| Qt::AlignHCenter); movie = new QMovie(":/topBar/icon/loading.gif"); movie->setScaledSize(QSize(100, 100)); movie->start(); sign->setMovie(movie); initLog = new QTextEdit(); initLog->setAlignment(Qt::AlignCenter); initLog->setStyleSheet(QString("background-color: transparent;" "border: 0px solid red;" "border-radius: 0px;")); initLog->setReadOnly(true); QFont font("微软雅黑", 8); initLog->setFont(font); //initLog->setPalette(palette); //initLog->setTextColor(QString("rgb(%1)").arg(sColor_Gold)); // 设置文字颜色为蓝色 initLog->setTextColor(Qt::white); initLog->append("测试测试"); glayout->addWidget(sign, 0, 0); glayout->addWidget(initLog, 1, 0); glayout->setRowStretch(0, 5); glayout->setRowStretch(1, 4); screenshot_ = QPixmap::grabWindow(widget->winId()); update(); // 更新widget以显示新的截图 } void stop() { delete sign; delete movie; } protected: void paintEvent(QPaintEvent* event) override { //if (screenshot_.isNull()) // return; //QImage image = screenshot_.toImage(); //image = image.convertToFormat(QImage::Format_RGB888); //cv::Mat originalMat = cv::Mat( // image.height(), // image.width(), // CV_8UC3, // image.bits(), // image.bytesPerLine()); //cv::Mat blurredMat; //cv::blur(originalMat, blurredMat, cv::Size(10, 10)); // 调整模糊半径以获得不同程度的模糊效果 //QPixmap blurredPixmap = cvMatToQPixmap(blurredMat); //QPainter painter(this); //painter.drawPixmap(0, 0, blurredPixmap); QWidget::paintEvent(event); // 调用父类的 paintEvent 函数,绘制控件本身 //// 在模糊图片上绘制文字 //QPalette palette; //palette.setColor(QPalette::WindowText, Qt::white); //QFont font("微软雅黑", 100, QFont::Bold); //QFont font2("微软雅黑", 90, QFont::Bold); //painter.setFont(font); //painter.setPen(Qt::black); //painter.drawText(this->rect(), Qt::AlignCenter, "WAIT"); //painter.setFont(font2); //painter.setPen(Qt::white); //painter.drawText(this->rect(), Qt::AlignCenter, "WAIT"); } private: QPixmap screenshot_; };