1 基本知識‘api
QPainter paint(this);//繪圖設備
QPixmap pix;//圖像工具類
pix.load("E:\\Qt_Projects\\build-Demo18-Desktop_Qt_5_10_1_MSVC2013_64bit-Debug\\debug\\imges\\logo.png");
paint.drawPixmap(0,0,100,100,pix);
// //縮放工具
//獲取原先的圖片大小
// qreal width=pix.width();
// qreal height=pix.height();字體
//設置縮放倍數ui
// pix.scaled(width*0.2,height*0.2,Qt::KeepAspectRatio);this
//旋轉
paint.translate(40,50);debug
//旋轉角度大小
paint.rotate(90);
paint.translate(-40,-50);
paint.drawPixmap(100,100,80,100,pix);圖片
//扭曲 ci
paint.shear(0.5, 0); //橫向扭曲
paint.drawPixmap(100, 0, 80, 100, pix);get
2 代碼it
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::paintEvent(QPaintEvent *){
//設置字體樣式 繪製文本 並將文本放於矩形中
// QPainter painter(this);
// QRectF rect(50,50,300,200);
// QFont font("宋體",16,QFont::Bold,true);
// font.setUnderline(true);
// font.setOverline(true);
// font.setCapitalization(QFont::SmallCaps);
// font.setLetterSpacing(QFont::AbsoluteSpacing,10);
// painter.setFont(font);
// painter.drawRect(rect);
// painter.setPen(Qt::red);
// painter.drawText(rect,Qt::AlignCenter,"Welcome use QT");
// 繪製路徑
// QPainterPath path;
// path.addRect(50,50,40,40);
// path.moveTo(QPointF(90,90));
// path.lineTo(200,200);
// QPainter paint(this );
// paint.drawPath(path);
//顯示圖片 後縮放圖片
//顯示
QPainter paint(this);
QPixmap pix;
pix.load("E:\\Qt_Projects\\build-Demo18-Desktop_Qt_5_10_1_MSVC2013_64bit-Debug\\debug\\imges\\logo.png");
paint.drawPixmap(0,0,100,100,pix);
// //縮放
// qreal width=pix.width();
// qreal height=pix.height();
// pix.scaled(width*0.2,height*0.2,Qt::KeepAspectRatio);
// paint.drawPixmap(80,80,pix);
//旋轉圖片
paint.translate(40,50);
paint.rotate(90);
paint.translate(-40,-50);
paint.drawPixmap(100,100,80,100,pix);
paint.shear(0.5, 0); //橫向扭曲
paint.drawPixmap(100, 0, 80, 100, pix);
}
demo 18 路徑: