Qt Creator module learning-2D drawing (simple drawing)

Qt Creator module learning-2D drawing

1. Simple drawing

Simple drawing is to draw simple shapes such
as circles, squares, rectangles, triangles, etc. As long as you pay attention to the following points, simple drawing is fine:
1. Specify the canvas and brush first, if you specify a brush for coloring, then you must paint the brush Give it to the painter. If you don't know the style and color, you can point to this function and check F1.

 QPainter p;//创建画家
    p.begin(this);//指定画布
    //绘图操作
    QPen pen;
    pen.setWidth(5);//粗细
    //pen.setColor(Qt::red);//设置颜色
    pen.setColor(QColor(14,10,123));//设置rgb颜色方式
    pen.setStyle(Qt::DashLine);//设置画笔形式
    p.setPen(pen);//画笔给绘画者
    //画直线
    p.drawLine(50,50,150,50);
    //画圆
    p.drawEllipse(QPoint(150,150),50,25);
    //画刷
    QBrush brush;
    brush.setColor(Qt::red);
    brush.setStyle(Qt::Dense1Pattern);
    p.setBrush(brush);
    //画矩形
    p.drawRect(150,150,100,50);
    p.end();

Guess you like

Origin blog.csdn.net/m0_50210478/article/details/108436355