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. Indicator
Qt 6.11 is out! See what's new in the release blog

Indicator

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 3.7k 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.
  • G Offline
    G Offline
    gauravsharma0190
    wrote on last edited by
    #1

    hello there
    I want to make an indicator. Mean When i Push the button, a green indicator see on my panel and if stop it i sees a red indicator there. So how to do that .Tell me
    Thank you.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      You could use a QLabel and show image?
      Just have a red/green image and use the setPixmap of QLabel
      when you push buttons.

      G 1 Reply Last reply
      2
      • G Offline
        G Offline
        gauravsharma0190
        wrote on last edited by
        #3

        Hello sir
        i worte it like this
        void mainwindow::on_start_button
        {
        QPixmap pix("/home/pi/Desktop/green.jpg")
        Qpixmap p("/home/pi/Desktop/red.jpg")
        ui->label->setPixmap(pix);
        .......
        .......
        Do some process....
        ....
        Now
        ui->label->setPixmap(p);
        }
        but when i push the button it won't change the label.

        mrjjM 1 Reply Last reply
        0
        • RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on last edited by Ratzz
          #4

          @gauravsharma0190
          I hope you use two pushbutton , one to start and one to stop?

          void mainwindow::on_start_button
          {
          QPixmap pix("/home/pi/Desktop/green.jpg")
          ui->label->setPixmap(pix);
          .......
          .......
          Do some process....
          ....
          }
          
          void mainwindow::on_stop_button
          {
          QPixmap  p("/home/pi/Desktop/red.jpg")
          ui->label->setPixmap(p);
          .......
          Do some process....
          ....
          }

          --Alles ist gut.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gauravsharma0190
            wrote on last edited by
            #5

            Yes i did same as you do but it didn't work for me .
            i don't understand where is the problem.
            i take a label name as label and put it blank ...
            But it doesn't change the .jpg files.

            1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              You could use a QLabel and show image?
              Just have a red/green image and use the setPixmap of QLabel
              when you push buttons.

              G Offline
              G Offline
              gauravsharma0190
              wrote on last edited by
              #6

              @mrjj
              How could i do that.
              i just do it like this
              void mainwindow::on_start_button
              {
              QPixmap pix("/home/pi/Desktop/green.jpg")
              Qpixmap p("/home/pi/Desktop/red.jpg")
              ui->label->setPixmap(pix);
              .......
              .......
              Do some process....
              ....
              Now
              ui->label->setPixmap(p);
              }
              but when i push the button it won't change the label.

              1 Reply Last reply
              0
              • KambizK Offline
                KambizK Offline
                Kambiz
                wrote on last edited by
                #7

                This code works correctly.

                void MainWindow::on_startButton_clicked()
                {
                    ui->label->setPixmap(QPixmap(":/img/online.png"));
                //do somthing...
                
                
                }
                
                void MainWindow::on_stopButton_clicked()
                {
                    ui->label->setPixmap(QPixmap(":/img/offline.png"));
                //do somthing...
                }
                
                

                .:.We speak a universal language that brings us together.:.

                1 Reply Last reply
                0
                • RatzzR Offline
                  RatzzR Offline
                  Ratzz
                  wrote on last edited by
                  #8

                  @gauravsharma0190
                  Show me the exact code.

                  --Alles ist gut.

                  1 Reply Last reply
                  1
                  • G gauravsharma0190

                    Hello sir
                    i worte it like this
                    void mainwindow::on_start_button
                    {
                    QPixmap pix("/home/pi/Desktop/green.jpg")
                    Qpixmap p("/home/pi/Desktop/red.jpg")
                    ui->label->setPixmap(pix);
                    .......
                    .......
                    Do some process....
                    ....
                    Now
                    ui->label->setPixmap(p);
                    }
                    but when i push the button it won't change the label.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @gauravsharma0190 said in Indicator:

                    Hi
                    When you do it in same function it dont really
                    work as u think as it never get time to draw.

                    void mainwindow::on_start_button
                    {
                    QPixmap pix("/home/pi/Desktop/green.jpg")
                    Qpixmap p("/home/pi/Desktop/red.jpg")
                    ui->label->setPixmap(pix); <<<<<<<<<<<<<<< prepare to draw it
                    Do some process....
                    Here the other is still not drawn
                    ui->label->setPixmap(p); <<<<<< prepare to draw this
                    }

                    You can try to insert
                    ..
                    ui->label->setPixmap(pix);
                    qApp->processEvents();

                    and it should change but would be better to with signals and slot as the other suggest.

                    http://www.informit.com/articles/article.aspx?p=1405544&seqNum=3

                    Also , do not use path like
                    /home/pi/Desktop/green.jpg
                    As it will stop working.
                    Use a resource file.
                    http://www.bogotobogo.com/Qt/Qt5_Resource_Files.php

                    1 Reply Last reply
                    2

                    • Login

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