Qt learning-image loading

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.