Qt键盘按下事件和定时器事件及事件的接收和忽略
定时器事件
//设置多少毫秒调用一次 1s=1000
timerId = this->startTimer(1000);
timerId2 = this->startTimer(500);
void MyWidget::timerEvent(QTimerEvent* t)
{
static int sec = 0;
//通过判断当前ID来实现不同定时器的调用时间
if(t->timerId() == this->timerId){
//隔一秒调用
QString text = QString("<center><h1>time out:%1</center></h1>").arg(sec++);
//鼠标进入事件时这个需要注销否则进入提示会被覆盖
//this->setText(text);
ui.label->setText(text);
if (sec == 5) {
//停止闹钟
this->killTimer(timerId);
}
}else if(t->timerId() == this->timerId2){
//隔0.5秒调用
QString text = QString("<center><h1>time out:%1</center></h1>").arg(sec++