该功能用来悬浮提示作用,悬浮2s之后自动关闭提示框
TispDlgView.h
#ifndef TIPSDLGVIEW_H
#define TIPSDLGVIEW_H
#include
#include “ui_TipsDlgView.h”
#include
class TipsDlgView : public QDialog
{
Q_OBJECT
public:
TipsDlgView(const QString &msg, QWidget *parent = 0);
~TipsDlgView();
/**
Description:
开启定时器
@param 无
@return 无
*/
void startTimer();
private:
Ui::TipsDlgView ui;
QTimer *m_pTimer;
private:
/**
Description:
初始化提示界面
@param msg 提示内容
@return 无
*/
void initFrame(const QString &msg);
};
#endif // TIPSDLGVIEW_H
/我是分割线*****************
TispDlgView.cpp
#include “TipsDlgView.h”
#pragma region 构造函数 析构函数
/***********************************************************************/
/ 构造函数 /
/***********************************************************************/
TipsDlgView::TipsDlgView(const QString &msg, QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_TranslucentBackground);
initFrame(msg);
m_pTimer = new QTimer(this);
m_pTimer->setSingleShot(true);
connect(m_pTimer, &QTimer::timeout, this, [=](){this->close();});
}
/***********************************************************************/
/ 析构函数 /
/***********************************************************************/
TipsDlgView::~TipsDlgView()
{
if (this->m_pTimer != Q_NULLPTR)
{
this->m_pTimer->deleteLater();
}
}
#pragma endregion
#pragma region
/***********************************************************************/
/ 启动定时器 /
/***********************************************************************/
void TipsDlgView::startTimer()
{
this->m_pTimer->start(1500);
}
#pragma endregion
#pragma region
/***********************************************************************/
/ 初始化提示界面 /
/***********************************************************************/
void TipsDlgView::initFrame(const QString &msg)
{
ui.m_tipsLabel->setText(msg);
}
#pragma endregion
/调用举例***/
TipsDlgView dlg(“Image capture succeeded.”, this->topLevelWidget());
//dlg.setAttribute(Qt::WA_ShowModal,true);
dlg.startTimer();
dlg.exec();