Construction
Class Dialog
Add a private member in dialog. h
void paintEvent(QPaintEvent *);
Add the following code to dialog. cpp:
void Dialog::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QPixmap pix;
pix.load("image/Win7.jpg");
painter.drawPixmap(0,0,100,100,pix);
}
In the painter06-build-desktop-Qt_4_8_1_for_Desktop _-_ mingw _ qt_sdk ____ \ debugdirectory, create a folder named imageimage win7.jpg.
The running program cannot always load images.
Hey, let's take a look at the compilation output.
Mingw32-make.exe [1]: Entering directory 'e:/My Documents/qt1/painter06-build-desktop-Qt_4_8_1_for_Desktop _-_ mingw _ qt_sdk ____'
Mingw32-make.exe [1]: Nothing to be done for 'first '.
Mingw32-make.exe [1]: Leaving directory 'e:/My Documents/qt1/painter06-build-desktop-Qt_4_8_1_for_Desktop _-_ mingw _ qt_sdk ____'
He only entered the painter06-build-desktop-Qt_4_8_1_for_Desktop _-_ mingw _ qt_sdk ____ 'directory, and did not enter the DEBUG directory, so of course he could not find the picture!
Now I know how to modify it.
In the program
pix.load("image/Win7.jpg");
Modify
pix.load("debug/image/Win7.jpg");
Okay! Pleasure!