QPixmap is not shown when run application in Qt

124 views Asked by At

Qt Designer allows me to add a .png file as a QLabel's pixmap, But it's only visible there, and not when running the app, and there are no errors.

This occurs when the picture is already included in a .qrc file, but loaded as a file and not as a resource (button "Choose Resource..." in the Property Editor)

1

There are 1 answers

0
Max Cury On

The problem can usually be solved if you add this file to .qrc and use resource path with a prefix you made.

This problem can occur when the picture is in the same project folder, even if it is added to .qrc, because Qt will shorten it's path in ui_filename.h and may do it incorrectly. Thus using file path instead of its alias or resource path is more insecure, Qt Designer will even show it properly, but you will not see it, while running, when ui_filename.h file will be used.

Summary: don't trust Qt Designer, just add everything to .qrc, especially if it is some exotic data format. You can try to open any other file from Designer->Property Editor->QLabel->pixmap->Choose File and see the list of available formats to use in the right bottom corner. For me it is: https://i.stack.imgur.com/2M1Le.png