Radio button and show an image



  • Hi

    Trying to show a different image when a radio button is toggled.
    I can change text in a lable and in a text box just fine, but to try to display an image won't work.
    Have been seaching the forum and the web, but sofar nothing.

    The help file is sometime just too abstract for me to understand

    @
    void MainWindow::on_radioButton_toggled(bool checked)
    {
    ui->label_3->setText("selected 1"); //change text in a lable
    ui->plainTextEdit->setPlainText("Selected 1"); //change text in a textbox

    ui->graphicsView->show('/images/picture1.png');   //doesn't work
    

    }@

    Any hints ?

    Thanks



  • The show method of QGraphicsView is not used that way.There are many ways you can show an image on a widget .The easiest I can come up is to load it on a QLabel.You can then do all you want in your function.Hope this helps



  • From your user interface position a QLabel on your GUI form and change your function to this:
    @ void MainWindow::on_radioButton_toggled(bool checked)
    {
    ui->label_3->setText("selected 1"); //change text in a lable
    ui->plainTextEdit->setPlainText("Selected 1"); //change text in a textbox

       QPixmap mypix ("/images/picture1.png");
       ui->label->setPixmap(mypix);
    }
    

    @

    You can check the doc to see what QPixmap is .Do everything you can to be as comfortable as you can with the doc.It is the best friend you can have with Qt:-)



  • Okay, I have no problem using a label, but what is the graphicsView box for then ?



  • It is an advanced concept of that allows you to structure your application to keep things organized.I suggest you stay away of that box for a while if you do not yet know the MVC architecture of Qt.


  • Moderators

    [quote author="fiddler" date="1367805141"]Okay, I have no problem using a label, but what is the graphicsView box for then ?[/quote]"QGraphicsView":http://qt-project.org/doc/qt-5.0/qtwidgets/qgraphicsview.html is for showing a "QGraphicsScene":http://qt-project.org/doc/qt-5.0/qtwidgets/qgraphicsscene.html. They are part of the "Graphics View Framework":http://qt-project.org/doc/qt-5.0/qtwidgets/graphicsview.html which is designed to manage many (thousands of) 2D objects, with features like zooming, stretching, rotating, click-and-drag, etc.

    If you want to show just one picture, use a QLabel :)


Log in to reply
 

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