Qpainter auto-adaptive drawing

Source: Internet
Author: User

Function declaration: void qpainter: drawimage (const qrectf & target, const qimage & image, const qrectf & source, QT: imageconversionflags flags = QT: autocolor)
Example:
Qrectf target (10.0, 20.0, 80.0, 60.0); // create a target rectangle
Qrectf source (0.0, 0.0, 70.0, 40.0); // create a source rectangle to specify the part to be displayed in the source Image File
Qimage image (":/images/myimage.png"); // create a qimage Class Object Image

Qpainter painter (this );
Painter. drawimage (target, image, source); // draw an image from the source image file (0.0, 0.0, 70.0, 40.0) to the painter device.

// (10.0, 20.0, 80.0, 60.0) position, adaptive size

   1: void ImageWidget::paintEvent(QPaintEvent *event) {

   2:     QPainter painter(this);

   3:     QRectF target(0, 0, this->width(), this->height());

   4:     if(!img.isNull())

   5:         painter.drawImage(target,img);

   6:         //painter.drawImage(0,0,img);

   7:     //img.save("test.bmp");

   8: }

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.