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. Display Image
QtWS25 Last Chance

Display Image

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 6 Posters 4.4k 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.
  • T Offline
    T Offline
    Tanuja
    wrote on last edited by
    #1

    Hi all,

    I am trying to display an image in qt. I have tried both methods like through code as well as through form. But the image is not getting displayed while running the code.
    Please help

    raven-worxR 1 Reply Last reply
    0
    • T Tanuja

      Hi all,

      I am trying to display an image in qt. I have tried both methods like through code as well as through form. But the image is not getting displayed while running the code.
      Please help

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Tanuja said in Display Image:

      Please help

      please help us first!
      How should anyone be able to help you by just saying "it doesn't work"?!?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      T 1 Reply Last reply
      4
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        How r u displaying the image ? Using QLabel or drawing it as Pixmap ?Please share the appropriate code snippet. As @raven-worx said, it helps people to help you.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        3
        • raven-worxR raven-worx

          @Tanuja said in Display Image:

          Please help

          please help us first!
          How should anyone be able to help you by just saying "it doesn't work"?!?

          T Offline
          T Offline
          Tanuja
          wrote on last edited by
          #4

          @raven-worx
          QPixmap pix("image path");
          ui->label->setpixmap(pix);
          ui->label->show();

          This is the code which I have written.
          Now can you please tell what is wrong in it.

          raven-worxR 1 Reply Last reply
          0
          • T Tanuja

            @raven-worx
            QPixmap pix("image path");
            ui->label->setpixmap(pix);
            ui->label->show();

            This is the code which I have written.
            Now can you please tell what is wrong in it.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @Tanuja said in Display Image:

            QPixmap pix("image path");

            How does the path look like exactly?
            What type of image?
            Qt version?
            Operating system?
            ...

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            T 1 Reply Last reply
            0
            • raven-worxR raven-worx

              @Tanuja said in Display Image:

              QPixmap pix("image path");

              How does the path look like exactly?
              What type of image?
              Qt version?
              Operating system?
              ...

              T Offline
              T Offline
              Tanuja
              wrote on last edited by
              #6

              @raven-worx
              This is the exact path:
              D:/Tanuja/QtProjects/pic.jpg

              Qt version is 5.6.2 and it's windows 32 but system

              raven-worxR 1 Reply Last reply
              0
              • T Tanuja

                @raven-worx
                This is the exact path:
                D:/Tanuja/QtProjects/pic.jpg

                Qt version is 5.6.2 and it's windows 32 but system

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @Tanuja said in Display Image:

                D:/Tanuja/QtProjects/pic.jpg

                i have to ask: you are sure that this file exists?

                If so, how did you run your application? out of QtCreator or already deployed (with Qt dlls)? In case of deployed make sure that the imageformat plugins are also deployed.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                T 1 Reply Last reply
                1
                • raven-worxR raven-worx

                  @Tanuja said in Display Image:

                  D:/Tanuja/QtProjects/pic.jpg

                  i have to ask: you are sure that this file exists?

                  If so, how did you run your application? out of QtCreator or already deployed (with Qt dlls)? In case of deployed make sure that the imageformat plugins are also deployed.

                  T Offline
                  T Offline
                  Tanuja
                  wrote on last edited by
                  #8

                  @raven-worx
                  Yes this image is present at the specified location.
                  And I am running my code from qt creator only.

                  Also, I have tried adding this image through form by giving image through the pixmap property of qlabel. But still on running the image is not displayed.

                  mrjjM jsulmJ 2 Replies Last reply
                  0
                  • T Tanuja

                    @raven-worx
                    Yes this image is present at the specified location.
                    And I am running my code from qt creator only.

                    Also, I have tried adding this image through form by giving image through the pixmap property of qlabel. But still on running the image is not displayed.

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

                    @Tanuja

                    The "Choose file" do NOT work with random paths.
                    it will become relative
                    "
                    label->setPixmap(QPixmap(QString::fromUtf8("../Pictures/taskbar3.png")));
                    "
                    But when run , the app is in the build folder and the pictures is NOT to be found with the relative path that is
                    from .pro location.

                    So use resource file or load them your self with the correct path.

                    Just look in the setupUI function. you can see the paths it will use.
                    Then check from your build folder. its no longer correct.

                    1 Reply Last reply
                    0
                    • T Tanuja

                      @raven-worx
                      Yes this image is present at the specified location.
                      And I am running my code from qt creator only.

                      Also, I have tried adding this image through form by giving image through the pixmap property of qlabel. But still on running the image is not displayed.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Tanuja Is the image file maybe corrupted? Did you check it in an image viewer?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by
                        #11

                        did you build and deploy the jpg image format plugin? Could you try with a .png image? if that is displayed then it's definitely the plugin

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        T 1 Reply Last reply
                        0
                        • VRoninV VRonin

                          did you build and deploy the jpg image format plugin? Could you try with a .png image? if that is displayed then it's definitely the plugin

                          T Offline
                          T Offline
                          Tanuja
                          wrote on last edited by
                          #12

                          @VRonin
                          It's done. I added a resource file and displayed image through it.

                          1 Reply Last reply
                          3

                          • Login

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