Solved paintEvent() why can't repaint() in QWidget?
-
"save.png" has been added in "images.qrc", its path is ":/save.png".
After the program runs,
During the program is running, I replaced "save.png" with anthor image (but same name with "save.png") and then click the "save image "button to trigger the left qwidget's repaint() slot, but the left qwidget don't change the background image. Why?
I don't understand why the qwidget don't change the background. So I try another way.
In paintEvent(), I replace the path ":/save.png" with "../BaslerWidget/save.png" , and make it, Why it succeed?(but it change the background before I trigger the left qwidget's repaint() , amazing.........)
Tips: BaslerWidget is my project name. the Build folder and the project folder are in the same level, you can see image below.
-
The image is compiled to the resource file at compile time. So changing at runtime has no effect.
qmake will produce make rules to generate a file called qrc_application.cpp that is linked into the application. This file contains all the data for the images and other resources as static C++ arrays of compressed binary data. http://doc.qt.io/qt-5/resources.html#compiled-in-resources
When you replace the path to "../BaslerWidget/save.png" you're not using the Qt resource system, instead you use the path relative to the application.
-
Thanks, I get it.