Timer event
-
i have 6 push buttons with some color and one ok push button
when i click ok push buttons color has to change to green with 5 seconds between each push button
i.e first push button color changes to green then after 5 seconds second should change and the first should go to its normal color then after 5 seconds third push button has to change and the second should go to its normal colorcan any body tell me how to implement it with qtimer
thank u
-
Try it.....
(in .h file )
public slots:
void OnRun();
int count;
QTimer *vptimer;(in .cpp file)
//In Constructor..
count=0;
vptimer=new QTimer(this);
vptimer->setInterval(1000);
connect(vptimer,SIGNAL(timeout()),this,SLOT(OnRun()));void MainWindow::OnRun()
{
++count;
if(count==5)
{
ui->pushButton_9->setStyleSheet("background-color:white");
ui->pushButton_4->setStyleSheet("background-color:red");
}
else if(count==10)
{
ui->pushButton_4->setStyleSheet("background-color:white");
ui->pushButton_5->setStyleSheet("background-color:black");
}
else if(count==15)
{
ui->pushButton_5->setStyleSheet("background-color:white");
ui->pushButton_6->setStyleSheet("background-color:green");
}
else if(count==20)
{
ui->pushButton_6->setStyleSheet("background-color:white");
ui->pushButton_7->setStyleSheet("background-color:yellow");
}
else if(count==25)
{
ui->pushButton_7->setStyleSheet("background-color:white");
ui->pushButton_8->setStyleSheet("background-color:blue");
}
else if(count==30)
{
ui->pushButton_8->setStyleSheet("background-color:white");
ui->pushButton_9->setStyleSheet("background-color:purple");
count=0;
}void MainWindow::on_pushButton_3_clicked()
{
//Ok button
vptimer->start();
} (Solved)