Radio button and show an image
-
wrote on 6 May 2013, 01:18 last edited by
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 textboxui->graphicsView->show('/images/picture1.png'); //doesn't work
}@
Any hints ?
Thanks
-
wrote on 6 May 2013, 01:39 last edited by
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
-
wrote on 6 May 2013, 01:50 last edited by
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 textboxQPixmap 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:-)
-
wrote on 6 May 2013, 01:52 last edited by
Okay, I have no problem using a label, but what is the graphicsView box for then ?
-
wrote on 6 May 2013, 02:01 last edited by
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.
-
[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 :)
1/6