Window painting in QT-image painting

Source: Internet
Author: User

In QT, qpixmap is used to represent an image. It supports loading in PNG and jpg formats.

Qpixmap PM ("C:/test.png"); or qpixmap PM; PM. Load ("C:/test/PNG ");

In QT, there are two image paths:

(1) images in the file system: use absolute or relative paths.

(2) files in the resource: Start with a colon, for example,/test/source/logo.jpg

Drawn parameters:

(1) source rectangle

You can draw all or part of a graph.

QRect source(0,0,ima_width,img_height);

(2) Target rectangle

It can be filled in all windows, or only part of the window can be filled.

QRect target(0,0,width/2,height/2);

Called functions:

painter.drawPixmap(target,m_picture,source)

Circlewidget. h

#ifndef CIRCLAWIDGET_H#define CIRCLAWIDGET_H#include <QFrame>#include<QTimer>#include<QPixmap>class CircleWidget:public QFrame{    Q_OBJECTpublic:    CircleWidget(QWidget *parent);    ~CircleWidget();private:    void paintEvent(QPaintEvent *event);private:    QPixmap m_picture;};#endif // CIRCLAWIDGET_H

Circlewidget. cpp

# include"circlewidget.h"#include<QPainter>CircleWidget::CircleWidget(QWidget *parent):QFrame(parent){   m_picture.load("/home/jun/untitled1/backimage.PNG");}CircleWidget::~CircleWidget(){}void CircleWidget::paintEvent(QPaintEvent *event){        QPainter painter(this);       int width=this->width();       int height=this->height();       QRect target(0,0,width,height);       int img_width=m_picture.width();       int img_height=m_picture.height();       QRect source (0,0,img_width,img_height);       painter.drawPixmap(target,m_picture,source);}

Result:

Window painting in QT-image painting

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.