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. No show of QPixmap
QtWS25 Last Chance

No show of QPixmap

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 6 Posters 5.1k 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.
  • Stan HuangS Offline
    Stan HuangS Offline
    Stan Huang
    wrote on last edited by Stan Huang
    #1

    Below is snippet of my codes which I expected it to show a specified BMP picture, but it doesn't. Anything I missed? I see that "to create ..." and "Created ..." shown, but see no picture shown. I confirmed the picture existing too.

    				printf ("to create a QPixmap\n");
    				pixmap_RoadFault = QPixmap("/exe/bv/image/sdkpic.jpg").scaled(74,45);
    				printf ("Created a QPixmap\n");
    				palette_RoadFault.setBrush(QPalette::Background, QBrush(pixmap_RoadFault));
                                        palette_RoadFault.setBrush(QPalette::Background, QBrush(pixmap_RoadFault));
    				ui->label_RoadFault->setGeometry(480,120,80,50);
    				ui->label_RoadFault->setPalette(palette_RoadFault);
    				ui->label_RoadFault->setAutoFillBackground(true)
    
    JKSHJ 1 Reply Last reply
    0
    • Stan HuangS Stan Huang

      Below is snippet of my codes which I expected it to show a specified BMP picture, but it doesn't. Anything I missed? I see that "to create ..." and "Created ..." shown, but see no picture shown. I confirmed the picture existing too.

      				printf ("to create a QPixmap\n");
      				pixmap_RoadFault = QPixmap("/exe/bv/image/sdkpic.jpg").scaled(74,45);
      				printf ("Created a QPixmap\n");
      				palette_RoadFault.setBrush(QPalette::Background, QBrush(pixmap_RoadFault));
                                          palette_RoadFault.setBrush(QPalette::Background, QBrush(pixmap_RoadFault));
      				ui->label_RoadFault->setGeometry(480,120,80,50);
      				ui->label_RoadFault->setPalette(palette_RoadFault);
      				ui->label_RoadFault->setAutoFillBackground(true)
      
      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Stan-Huang It's not clear from your snippet: What does palette_RoadFault do?

      The quickest way to show your QPixmap is to put inside a QLabel and show() the QLabel.

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

      Stan HuangS 1 Reply Last reply
      1
      • JKSHJ JKSH

        @Stan-Huang It's not clear from your snippet: What does palette_RoadFault do?

        The quickest way to show your QPixmap is to put inside a QLabel and show() the QLabel.

        Stan HuangS Offline
        Stan HuangS Offline
        Stan Huang
        wrote on last edited by
        #3

        @JKSH I updated the snippet. I don't quite understand it because it was from previous engineer and he said this is not verified codes. I am still new Qt user.

        JKSHJ 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          When I see your other (deleted) question here https://forum.qt.io/topic/99218 I would guess /exe/bv/image/sdkpic.jpg does not exist or is not readable. You can check if the QPixmap is empty: http://doc.qt.io/qt-5/qpixmap.html#isNull

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          Stan HuangS 1 Reply Last reply
          3
          • Christian EhrlicherC Christian Ehrlicher

            When I see your other (deleted) question here https://forum.qt.io/topic/99218 I would guess /exe/bv/image/sdkpic.jpg does not exist or is not readable. You can check if the QPixmap is empty: http://doc.qt.io/qt-5/qpixmap.html#isNull

            Stan HuangS Offline
            Stan HuangS Offline
            Stan Huang
            wrote on last edited by
            #5

            @Christian-Ehrlicher You're right in saying non-existence of picture to be shown being the cause of issue stated at the deleted one. But for this one, I'm sure it's existent and readable.

            Christian EhrlicherC 1 Reply Last reply
            0
            • Stan HuangS Stan Huang

              @JKSH I updated the snippet. I don't quite understand it because it was from previous engineer and he said this is not verified codes. I am still new Qt user.

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              @Stan-Huang said in No show of QPixmap:

              I am still new Qt user.

              Then it's best to study simple examples.

              Create a new, small Qt Widgets application:

              #include <QApplication>
              #include <QPixmap>
              #include <QLabel>
              
              int main (int argc, char **argv)
              {
                  QApplication app(argc, argv);
              
                  QPixmap pixmap_RoadFault("/exe/bv/image/sdkpic.jpg");
              
                  QLabel label;
                  label.setPixmap(pixmap_RoadFault);
                  label.show();
              
                  return app.exec();
              }
              

              By the way, I've restored your other post. Please don't delete posts after you have found a solution.

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

              Stan HuangS 1 Reply Last reply
              4
              • Stan HuangS Stan Huang

                @Christian-Ehrlicher You're right in saying non-existence of picture to be shown being the cause of issue stated at the deleted one. But for this one, I'm sure it's existent and readable.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Stan-Huang said in No show of QPixmap:

                I'm sure it's existent and readable.

                Although you are 'sure' you should check it with the function I pointed you to ...

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                Stan HuangS 1 Reply Last reply
                0
                • JKSHJ JKSH

                  @Stan-Huang said in No show of QPixmap:

                  I am still new Qt user.

                  Then it's best to study simple examples.

                  Create a new, small Qt Widgets application:

                  #include <QApplication>
                  #include <QPixmap>
                  #include <QLabel>
                  
                  int main (int argc, char **argv)
                  {
                      QApplication app(argc, argv);
                  
                      QPixmap pixmap_RoadFault("/exe/bv/image/sdkpic.jpg");
                  
                      QLabel label;
                      label.setPixmap(pixmap_RoadFault);
                      label.show();
                  
                      return app.exec();
                  }
                  

                  By the way, I've restored your other post. Please don't delete posts after you have found a solution.

                  Stan HuangS Offline
                  Stan HuangS Offline
                  Stan Huang
                  wrote on last edited by
                  #8

                  @JKSH It still doesn't work.

                  jsulmJ 1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

                    What does file /exe/bv/image/sdkpic.jpg return ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    Stan HuangS 1 Reply Last reply
                    1
                    • Stan HuangS Stan Huang

                      @JKSH It still doesn't work.

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

                      @Stan-Huang Come on, be a bit more proactive!
                      Did you check whether your pixmap is null as @Christian-Ehrlicher suggested?
                      Also, /exe/bv/image/sdkpic.jpg is an absolute path and looks strange - are you REALLY sure it is correct?
                      Try what @SGaist suggested.

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

                      1 Reply Last reply
                      1
                      • SGaistS SGaist

                        Hi,

                        What does file /exe/bv/image/sdkpic.jpg return ?

                        Stan HuangS Offline
                        Stan HuangS Offline
                        Stan Huang
                        wrote on last edited by Stan Huang
                        #11

                        @SGaist The return of "file /exe/bv/image/sdkpic.jpg" is:

                        root@mitacimx6:/opt/BVDemo/smartbox# file /exe/bv/image/sdkpic.jpg
                        /exe/bv/image/sdkpic.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1108x1478, frames 3

                        JKSHJ 1 Reply Last reply
                        0
                        • Stan HuangS Stan Huang

                          @SGaist The return of "file /exe/bv/image/sdkpic.jpg" is:

                          root@mitacimx6:/opt/BVDemo/smartbox# file /exe/bv/image/sdkpic.jpg
                          /exe/bv/image/sdkpic.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1108x1478, frames 3

                          JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #12

                          @Stan-Huang said in No show of QPixmap:

                          The return of "file /exe/bv/image/sdkpic.jpg" is:

                          root@mitacimx6:/opt/BVDemo/smartbox# file /exe/bv/image/sdkpic.jpg
                          /exe/bv/image/sdkpic.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1108x1478, frames 3

                          OK, it looks like the file is valid.

                          Next, check if Qt can understand the file format. What do you get when you call
                          qDebug() << QImageReader::supportedImageFormats() ? (remember #include <QDebug> and #include <QImageReader>)

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

                          Stan HuangS 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            @Stan-Huang said in No show of QPixmap:

                            I'm sure it's existent and readable.

                            Although you are 'sure' you should check it with the function I pointed you to ...

                            Stan HuangS Offline
                            Stan HuangS Offline
                            Stan Huang
                            wrote on last edited by
                            #13

                            @Christian-Ehrlicher setPixmap(pixmap_RoadFault) is void, so no return.

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Stan-Huang said in No show of QPixmap:

                              setPixmap(pixmap_RoadFault) is void, so no return.

                              Pleae read my link: http://doc.qt.io/qt-5/qpixmap.html#isNull - no setPixmap() but QPixmap::isNull() ...

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              Stan HuangS 1 Reply Last reply
                              0
                              • JKSHJ JKSH

                                @Stan-Huang said in No show of QPixmap:

                                The return of "file /exe/bv/image/sdkpic.jpg" is:

                                root@mitacimx6:/opt/BVDemo/smartbox# file /exe/bv/image/sdkpic.jpg
                                /exe/bv/image/sdkpic.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1108x1478, frames 3

                                OK, it looks like the file is valid.

                                Next, check if Qt can understand the file format. What do you get when you call
                                qDebug() << QImageReader::supportedImageFormats() ? (remember #include <QDebug> and #include <QImageReader>)

                                Stan HuangS Offline
                                Stan HuangS Offline
                                Stan Huang
                                wrote on last edited by
                                #15

                                @JKSH The return is:
                                ("bmp", "cur", "gif", "ico", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "xbm", "xpm")

                                1 Reply Last reply
                                0
                                • Christian EhrlicherC Christian Ehrlicher

                                  @Stan-Huang said in No show of QPixmap:

                                  setPixmap(pixmap_RoadFault) is void, so no return.

                                  Pleae read my link: http://doc.qt.io/qt-5/qpixmap.html#isNull - no setPixmap() but QPixmap::isNull() ...

                                  Stan HuangS Offline
                                  Stan HuangS Offline
                                  Stan Huang
                                  wrote on last edited by
                                  #16

                                  @Christian-Ehrlicher said in No show of QPixmap:

                                  setPixmap

                                  QPixmap::isNull() returned 'false'

                                  J.HilkJ 1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    What if you set the pixmap directly on the QLabel rather than using a brush in the palette ?

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    Stan HuangS 2 Replies Last reply
                                    0
                                    • Stan HuangS Stan Huang

                                      @Christian-Ehrlicher said in No show of QPixmap:

                                      setPixmap

                                      QPixmap::isNull() returned 'false'

                                      J.HilkJ Offline
                                      J.HilkJ Offline
                                      J.Hilk
                                      Moderators
                                      wrote on last edited by J.Hilk
                                      #18

                                      @Stan-Huang
                                      It's not quite clear from the code you posted, but are you sure that palette_RoadFault is not set to something invalid somewhere else in your code, and that palette_RoadFault persists outside the scope of your function?

                                      QBrush expects a const reference to a QPixmap, I don't think it will take ownership or make a copy of the QPixmap for drawing.


                                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                      Q: What's that?
                                      A: It's blue light.
                                      Q: What does it do?
                                      A: It turns blue.

                                      1 Reply Last reply
                                      0
                                      • SGaistS SGaist

                                        What if you set the pixmap directly on the QLabel rather than using a brush in the palette ?

                                        Stan HuangS Offline
                                        Stan HuangS Offline
                                        Stan Huang
                                        wrote on last edited by
                                        #19

                                        @SGaist I did it but still doesn't work:
                                        ui->label->setGeometry(20,20,60,20);
                                        ui->label->setPixmap(pixmap_RoadFault);
                                        ui->label->show();

                                        1 Reply Last reply
                                        0
                                        • SGaistS SGaist

                                          What if you set the pixmap directly on the QLabel rather than using a brush in the palette ?

                                          Stan HuangS Offline
                                          Stan HuangS Offline
                                          Stan Huang
                                          wrote on last edited by
                                          #20

                                          @SGaist I did but still doesn't work:

                                          				ui->label->setGeometry(20,20,60,20);
                                          				ui->label->setPixmap(pixmap_RoadFault);
                                          				ui->label->show();
                                          
                                          1 Reply Last reply
                                          0

                                          • Login

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