#include "DialogUserMsg.h" #include "Common.h" DialogUserMsg::DialogUserMsg(QWidget *parent) : QDialog(parent) { ui.setupUi(this); this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); this->hide(); ui.editMsg->setProperty("noinput", true); ui.labelTime->setProperty("noinput", true); m_timer = new QTimer(this); m_TimeCheck = new QTimer(this); m_nTimeCheck = 3; QString str; str = QString("窗口将在 [ %1 ] 秒后关闭").arg(m_nTimeCheck); ui.labelTime->setText(str); m_TimeCheck->start(1000);//时间1秒 connect(m_TimeCheck, SIGNAL(timeout()), this, SLOT(onTimeCheck())); connect(this, SIGNAL(sigAddMassage(QString)), this, SLOT(on_AddMessage(QString))); connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeupDestroy())); } DialogUserMsg::~DialogUserMsg() { } void DialogUserMsg::on_AddMessage(QString str) { ui.editMsg->append(str); ui.editMsg->moveCursor(QTextCursor::End); this->move(1, 100); this->show(); m_timer->start(3000);//时间5秒 m_timer->setSingleShot(true);//仅触发一次 m_nTimeCheck = 3; str = QString("窗口将在 [ %1 ] 秒后关闭").arg(m_nTimeCheck); ui.labelTime->setText(str); } void DialogUserMsg::AddMessage(QString str) { emit sigAddMassage(str); } void DialogUserMsg::on_buttonOk_clicked() { ui.editMsg->clear(); this->hide(); } void DialogUserMsg::onTimeupDestroy() { ui.editMsg->clear(); this->hide(); } void DialogUserMsg::onTimeCheck() { if (m_nTimeCheck < 0) { return; } QString str ; str = QString( "窗口将在 [ %1 ] 秒后关闭").arg(m_nTimeCheck); ui.labelTime->setText( str); m_nTimeCheck--; }