Indicator



  • 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.


  • Qt Champions 2017

    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.



  • 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.



  • @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....
    ....
    }


  • 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.



  • @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.



  • 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...
    }
    
    


  • @gauravsharma0190
    Show me the exact code.


  • Qt Champions 2017

    @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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.