qt delay on off pixmap -
hy qt master..
i wanna make label (pixmap) on off on off on , soon, how can that??
i have try use code :
sleeper::sleep(2); ui->label->setpixmap(qpixmap("c:/users/evan/pictures/new folder/85.png")); sleeper::sleep(2); ui->label->setpixmap(qpixmap("c:/users/evan/pictures/new folder/87.png")); sleeper::sleep(2); ui->label->setpixmap(qpixmap("c:/users/evan/pictures/new folder/85.png")); sleeper::sleep(2); ui->label->setpixmap(qpixmap("c:/users/evan/pictures/new folder/87.png")); that not work? how can solved that? all
this problem :
if(i==4) { qtimer *timer1 = new qtimer(this); connect(timer1, signal(timeout()), this, slot(ontimer())); timer1->start(1000); blink=true; port->write(send); } else if(i==5) { ui->label->setpixmap(qpixmap("../../picture/green.png")); port->write(send); } ............................................
void traffic1::ontimer() { ui->label->setpixmap(qpixmap(blink ? "../../picture/dark.png" : "../../picture/yellow.png")); blink = !blink; } when i=4, qtimer run when i=5 qtimer still active.
first add boolean member variable bool blink;, create qtimer , connect it's timeout() signal slot function below:
// constructor: yourclass::yourclass() { qtimer *timer = new qtimer(this); connect(timer, signal(timeout()), this, slot(ontimer())); timer->start(1000); blink = false; } ........
void yourclass::ontimer() { ui->label->setpixmap(qpixmap(blink ? "c:/users/evan/pictures/new folder/85.png" : "c:/users/evan/pictures/new folder/87.png")); blink = !blink; } edit: if want control timer, should declare in header of class first
class yourclass { qtimer *timer; ... }; and when want create it:
yourclass::yourclass() { timer = new qtimer(this); connect(timer, signal(timeout()), this, slot(ontimer())); timer->start(1000); blink = false; } for stopping it:
timer->stop();
Comments
Post a Comment