繪圖設(shè)備
QPixmap:針對(duì)屏幕進(jìn)行優(yōu)化了,和平臺(tái)相關(guān)色罚,不能對(duì)圖片進(jìn)行修改
QInage:和平臺(tái)無(wú)關(guān)碰缔,可以對(duì)圖片進(jìn)行修改,在線程中繪圖
QPicture:保存繪圖的狀態(tài)(二進(jìn)制文件)
頭文件:#include <QPainter>
1.
widget.h
protected:
? ? //重寫(xiě)繪圖事件戳护,虛函數(shù)
? ? //如果在窗口繪圖金抡,必須放在繪圖事件里實(shí)現(xiàn)
? ? //繪圖事件內(nèi)部自動(dòng)調(diào)用,窗口需要重繪的時(shí)候(狀態(tài)改變)
void paintEvent(QPaintEvent *);
widget.cpp
void myWidget::paintEvent(QPaintEvent *)
{
? ? //QPainter p(this);
? ? QPainter p;//創(chuàng)建畫(huà)家對(duì)象
? ? p.begin(this);//指定當(dāng)前窗口為繪圖設(shè)備
? ? //繪圖操作
? ? //p.drawxxx();
? ? //畫(huà)背景圖
? ? p.drawPixmap(0,0,width(),height(),QPixmap("../Image/22.jpg"));
????//p.drawPixmap(rect(),QPixmap("../Image/22.jpg")); //rect會(huì)直接獲得所在矩形框四個(gè)邊
? ? p.end();
}
頭文件?
2.窗口自動(dòng)重繪
private:? int x;
? ??????void myWidget::on_pushButton_clicked()
{
? ? x += 20;
? ? if(x > width())
? ? {
? ? ? ? x = 0;
? ? }
? ? //刷新窗口腌且,讓窗口重繪
? ? update();//間接調(diào)用
}
3.QPixmap -->QImage
? ? Qpainter p(this);
? ? QPixmap pixmap;
? ? pixmap.load("../Image/face.png");
? ? p.drawImage(0,0,tempImage);
? 4.QImage-->QPixmaop
? ? QImage image;
? ? image.load("路徑");
? ? QPixmap tempPixmap = QPixmap::formImage(image);
? ? p.drawPixmap(100,0,tempPixmap);