|
你都用上qt这么高大上的东西了,还用delay这种方式?
给你个实例,我没法点灯,就用一个label来显示红色,蓝色代替了
有用代码
.h
QTimer *timer;
bool shine;
public slots:
void PushButtonFlicker();
void TimerSlot();
.cpp
shine = true;
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(TimerSlot()));
connect(ui->pushButtonFlicker,SIGNAL(clicked()),this,SLOT(PushButtonFlicker()));
void Dialog:ushButtonFlicker()
{
timer->start(1000);
}
void Dialog::TimerSlot()
{
if(shine)
{
ui->labelFlicker->setStyleSheet("background-color: rgb(255, 0, 0)");
}
else
{
ui->labelFlicker->setStyleSheet("background-color: rgb(0, 0, 255)");
}
shine = !shine;
}
|
|