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. Radio button and show an image

Radio button and show an image

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.2k Views
  • 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.
  • F Offline
    F Offline
    fiddler
    wrote on 6 May 2013, 01:18 last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      musimbate
      wrote on 6 May 2013, 01:39 last edited by
      #2

      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

      Why join the navy if you can be a pirate?-Steve Jobs

      1 Reply Last reply
      0
      • M Offline
        M Offline
        musimbate
        wrote on 6 May 2013, 01:50 last edited by
        #3

        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:-)

        Why join the navy if you can be a pirate?-Steve Jobs

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fiddler
          wrote on 6 May 2013, 01:52 last edited by
          #4

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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            musimbate
            wrote on 6 May 2013, 02:01 last edited by
            #5

            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.

            Why join the navy if you can be a pirate?-Steve Jobs

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JKSH
              Moderators
              wrote on 6 May 2013, 02:02 last edited by
              #6

              [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 :)

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0

              1/6

              6 May 2013, 01:18

              • Login

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