自学qt之QPainter

drawPoint() drawArc()
drawLine() drawChord()
drawPolyline()drawPie()
drawPoints()drawText()
drawLines()drawPixmap()
drawPolygon()drawPath()
drawRect()
drawRoundRect()
drawEllipse()

protected:
void painEvent(QPainEvent *);//继承下来的函数
void painEvent(QPointEvent *)
{
QPainter painter(this);//在哪里画
painter.drawRect(100,100,200,200);//左上角,宽度和高度
painter.drawLine(50,50,500,50);//起点和终点
painter.drawLine(QPoint(20,30),QPoint(20,400));
painter.setBrush(QBrush:(Qt::blue));//设置画刷
painter.setBrush(QBrush(Qt::white));
painter.drawRect(this->rect());//画背景
painter.setBrush(QBrush:(Qt::red));
painter.drawEllipse(Qpoint(200,400),100,70);//画椭圆
QPixmap pix(“dog.jpg”);
painter.drawPixmap(400,100,pix);
painter.drawText(400,420,”软件开发”);
QFont font;
font.setFamily(“黑体”);
font.setPointSize(22);
painter.setFont(font);
painter.drawText(400,420,”软件开发”);
painter.setPen(QPen(Qt::green));//一开始设置不是最后
}

enum shape{Line,Ellipse,Pie};
shape drawShape;//枚举变量
this->drawShape=Widget::line;
painter.setRenderHint(Qpainter::Antialiasing,true);//反走样
painter.setPen(QPen(Qt::red,20,QT::SolidLine));//实心线  默认方帽子
painter.setPen(QPen(Qt::red,20,Qt::SolidLine,Qt::RoundCap));//加上圆帽子
painter.setPen(QPen(Qt::red,20,Qt::SolidLine,Qt::SquareCap));//加上方帽子
update();//切记这个函数  槽函数里面这个
Qt::DashDotLine;//点划线
painter.drawPie(80,80,400,240,60*16,270*16);//最后两个是角度,画饼  一定要乘16
  MiterJoin     尖的连接的地方
Qt::RoundJoin,//圆的连接地方 Qt::BevelJoin;//平的
painter.setBrush(QBrush(Qt::green,Qt::VerPattern));//垂直线做画刷
                                  Qt::HorPattern;//横线
                                  Qt::BDiagPattern;//后斜线
                                  Qt::FDiagPattern;//前斜线
                                  Qt::Den//各种
线性渐变 QLinearGradient
辐射渐变 QredialGradient
锥形渐变 QConicalGradient
纹理画刷
#ifndef RENDERLABEL_H
#define RENDERLABEL_H
#include <QLabel>
clasee RenderLabel:public QLabel
{
  Q_OBJECT
    enum BrudhPattern{LinearGradient,RadialGradient,ConicalGradient,TexturePattern};
  public:
    RenderLabel(QWidget *parent=0);
    void setBrushPattern(BrushPattern brushPattern );
  protected:
    void painEvent(QPaintEvent *);
  protected:
    BrushPattern brushPattern;
}
RenderLabel::RenderLabel(QWidget *parent):QLabel(parent)
{

}
this->renderLabel=new RenderLabel(this);
this->renderLabel->setGeometry(0,0,500,500);//定位在哪
void RenderLabel::setBrushPattern(BrushPattern brushPattern)
{
  this->brushPattern=brushPattern;
}
void RenderLabel::paintEvent(QPaintEvent *)
{
    QLinearGradient linearGradient(10,10,400,200);//大小和范围 左上角 宽度和高度
    linearGradient.setColorAt(0,Qt::red);
    linearGradient.setColorAt(0.3,Qt::blue);
    linearGradient.setColorAt(1,Qt::yellow);
    painter.setBrush(linearGradient);
}
painter.setBrush(QBrush(QPixmap(":/images/tt.jpg")));
painter.drawEllipse(10,10,500,500);//图片当画刷
QPainter painter(this);
painter.fillRect(rect(),Qt::white);//画背景

你可能感兴趣的:(qt)