Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved No show of QPixmap

    General and Desktop
    6
    24
    2935
    Loading More Posts
    • 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 Huang
      Stan Huang last edited by 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)
      
      JKSH 1 Reply Last reply Reply Quote 0
      • JKSH
        JKSH Moderators @Stan Huang last edited by

        @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 Huang 1 Reply Last reply Reply Quote 1
        • Stan Huang
          Stan Huang @JKSH last edited by

          @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.

          JKSH 1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            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 has to stay free or it will die.

            Stan Huang 1 Reply Last reply Reply Quote 3
            • Stan Huang
              Stan Huang @Christian Ehrlicher last edited by

              @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 Ehrlicher 1 Reply Last reply Reply Quote 0
              • JKSH
                JKSH Moderators @Stan Huang last edited by

                @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 Huang 1 Reply Last reply Reply Quote 4
                • Christian Ehrlicher
                  Christian Ehrlicher Lifetime Qt Champion @Stan Huang last edited by

                  @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 has to stay free or it will die.

                  Stan Huang 1 Reply Last reply Reply Quote 0
                  • Stan Huang
                    Stan Huang @JKSH last edited by

                    @JKSH It still doesn't work.

                    jsulm 1 Reply Last reply Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      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 Huang 1 Reply Last reply Reply Quote 1
                      • jsulm
                        jsulm Lifetime Qt Champion @Stan Huang last edited by jsulm

                        @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 Reply Quote 1
                        • Stan Huang
                          Stan Huang @SGaist last edited by 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

                          JKSH 1 Reply Last reply Reply Quote 0
                          • JKSH
                            JKSH Moderators @Stan Huang last edited by

                            @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 Huang 1 Reply Last reply Reply Quote 0
                            • Stan Huang
                              Stan Huang @Christian Ehrlicher last edited by

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

                              1 Reply Last reply Reply Quote 0
                              • Christian Ehrlicher
                                Christian Ehrlicher Lifetime Qt Champion last edited by

                                @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 has to stay free or it will die.

                                Stan Huang 1 Reply Last reply Reply Quote 0
                                • Stan Huang
                                  Stan Huang @JKSH last edited by

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

                                  1 Reply Last reply Reply Quote 0
                                  • Stan Huang
                                    Stan Huang @Christian Ehrlicher last edited by

                                    @Christian-Ehrlicher said in No show of QPixmap:

                                    setPixmap

                                    QPixmap::isNull() returned 'false'

                                    J.Hilk 1 Reply Last reply Reply Quote 0
                                    • SGaist
                                      SGaist Lifetime Qt Champion last edited by

                                      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 Huang 2 Replies Last reply Reply Quote 0
                                      • J.Hilk
                                        J.Hilk Moderators @Stan Huang last edited by J.Hilk

                                        @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

                                        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                                        1 Reply Last reply Reply Quote 0
                                        • Stan Huang
                                          Stan Huang @SGaist last edited by

                                          @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 Reply Quote 0
                                          • Stan Huang
                                            Stan Huang @SGaist last edited by

                                            @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 Reply Quote 0
                                            • First post
                                              Last post