当前位置:网站首页>QT brushes and brushes

QT brushes and brushes

2022-06-13 04:55:00 qq_ thirty-nine million two hundred and eighty thousand seven h

Qt Introduction to drawing system

Qt Provides a powerful 2D Drawing system , You can use the same API Drawing on screen and drawing equipment , It's mainly based on QPainter、QPaintDevice and QPaintEngine These three categories .

QPainter Used to perform drawing operations ; QPaintDevice Provide drawing equipment , It's an abstraction of two-dimensional space , have access to QPainter Draw on it ; QPaintEngine Some interfaces are provided , It can be used for QPainter Drawing on different devices .

stay Qt In the drawing system , from QPainter To complete the specific drawing operation .QPainter Generally in the redrawing event of a part (Paint Event) Processing function of paintEvent() Drawing in :

The first thing to do is to create QPainter object ; And then draw the graph ; Finally destroy QPainter object .

QPainter Usage mode

1.QPainter In the constructor ,parent Specify the drawing object ( equipment );QPainter Automatically call... In the constructor begin function , Indicates the beginning of the drawing , stay QPainter Call in the destructor end() Function ends drawing .

    QRectF rectangle(10.0, 20.0, 80.0, 60.0);
    int startAngle = 30 * 16;
    int spanAngle = 120 * 16;
    QPainter painter(this);
    painter.drawArc(rectangle, startAngle, spanAngle);

2. When constructing , Do not specify... In the constructor parent( Drawing objects ); Display call begin(parent) Specify the drawing device .

At the end of the drawing , Display call end() function .

    QRectF rectangle(10.0, 20.0, 80.0, 60.0);
    int startAngle = 30 * 16;
    int spanAngle = 120 * 16;
    QPainter painter;
    painter.begin(this); // Designated equipment 
    painter.drawArc(rectangle, startAngle, spanAngle);
    painter.end();

Brushes and brushes

The brush specifies the style of the outline of the pattern

Brush specifies the fill pattern of the pattern

Brushes used

    // Use the brush , Set brush style 
    QPen pen(Qt::red,6, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin);
    painter.setPen(pen);
    painter.drawArc(rectangle, startAngle, spanAngle);

Use a brush

    //  Create a brush , Set the style of the brush 
    QBrush brush(QColor(0, 0, 255), Qt::Dense4Pattern);
    //  Use the brush 
    painter.setBrush(brush);
    //  Draw the ellipse 
    painter.drawEllipse(220, 20, 50, 50);

原网站

版权声明
本文为[qq_ thirty-nine million two hundred and eighty thousand seven h]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280518242089.html