Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Timer event
Qt 6.11 is out! See what's new in the release blog

Timer event

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janaki
    wrote on last edited by
    #1

    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 color

    can any body tell me how to implement it with qtimer

    thank u

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      I suggest to use a QTimer and QStateMachine

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • IamSumitI Offline
        IamSumitI Offline
        IamSumit
        wrote on last edited by
        #3

        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)

        Be Cute

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved