您的位置:首页 > 其它

定时关闭消息对话框

2014-12-04 20:34 471 查看
class QTimeDialog : public QDialog

{public:

QTimeDialog (const QString & str,QWidget *parent = NULL);

~QTimeDialog ();

static void show(const QString & msg, QWidget *parent = NULL);

protected:

void startShow();

virtual void timerEvent(QTimerEvent * event);

private:

QLabel * m_display;

QHBoxLayout * m_layout;

QString m_msg;

int m_timeCount;

int m_timerId;

static QTimeDialog * _timeDialg_;

};

//

#define MAX_MSG_SHOW 60

//----------------------------------------------------------------------------------

QTimeDialog *::QTimeDialog _timeDialg_ = NULL;

//-----------------------------------------------------------------------------

QTimeDialog ::(QTimeDialog const QString & str, QWidget *parent)

:m_msg(str)

,QDialog(parent)

,m_timeCount(0)

,m_timerId(0)

{

m_display = new QLabel;

m_layout = new QHBoxLayout;


m_layout->addWidget(m_display);


this->setLayout(m_layout);

}


QTimeDialog ::~QTimeDialog()

{

this->killTimer(m_timerId);

_timeDialg_ = NULL;

}


void QTimeDialog::show(const QString & msg,QWidget * parent)

{

if(_timeDialg_)

    {

_timeDialg_->m_timeCount = 0;

_timeDialg_->m_display->setText(msg);

    }

else

    {

_timeDialg_ = new GZLTimeDialog(msg,parent);

_timeDialg_->startShow();

    }

}


void QTimeDialog::timerEvent(QTimerEvent * event)

{

m_timeCount++;

if(m_timeCount > MAX_MSG_SHOW)

    {

m_timeCount = 0;

this->close();

    }

}


void QTimeDialog::startShow()

{

QDialog::show();

m_timerId = this->startTimer(1000);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: