代码拉取完成,页面将自动刷新
#include "lightMessage.h"
#include <QLabel>
#include <QTimer>
#include <QPropertyAnimation>
#include <QDesktopWidget>
LightMessage::LightMessage(QWidget *parent,QString info, QString strFontSize, QString strColor) : QFrame(parent)
{
//窗口设置
//int width = 200;
//int height = 134;
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
this->setAttribute(Qt::WA_TranslucentBackground); //设置窗体背景透明
this->resize(200,134);
//刷背景图片
QLabel *pLabelImg = new QLabel(this);
pLabelImg->resize(width(),height());
pLabelImg->setGeometry(0,0,width(),height());
QImage img(":/new/prefix1/resource/lightMessage.png");
QImage img2 = img.scaled(width(),height(),Qt::KeepAspectRatio);
pLabelImg->setPixmap(QPixmap::fromImage(img2));
//刷文字
QLabel *pLabelStr = new QLabel(this);
pLabelStr->setAlignment(Qt::AlignCenter);
pLabelStr->setStyleSheet(QString("QLabel{color:%1;font:%2 SimHei;border-radius:5px;}")
.arg(strColor).arg(strFontSize));
pLabelStr->setText(info);
pLabelStr->adjustSize();
pLabelStr->setGeometry(width()/25,height()/13.5,width()/1.45,height()/2.4);
}
void LightMessage::information(QWidget *parent,QString info, int time, QString strFontSize, QString strColor)
{
LightMessage *widgetPtr = new LightMessage(parent,info,strFontSize,strColor);
if(parent)
{
int x = parent->pos().x();
int y = parent->pos().y() - widgetPtr->height();
widgetPtr->move(x,y-2);
}
if(time < 1100) time = 1100;
QTimer::singleShot(time-1000,widgetPtr,[=]()
{
QPropertyAnimation *pAnimation = new QPropertyAnimation(widgetPtr,"windowOpacity",widgetPtr);
pAnimation->setDuration(1000);
pAnimation->setEasingCurve(QEasingCurve::InCirc);
pAnimation->setStartValue(1.0);
pAnimation->setEndValue(0.0);
pAnimation->start();
connect(pAnimation,&QPropertyAnimation::finished,[=]{
delete widgetPtr;
});
});
widgetPtr->show();
}
#include <QMouseEvent>
void LightMessage::mousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event)
this->close();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。