Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

c++ - QWidget:: paintEvent() - objects drawn with QPainter are clipped

I have simple Qt Widgets Application. I call update (rect) in mouseMoveEvent(). I call drawArc() and drawRect() in the paintEvent(). Function drawArc() draws the circle little bit smaller then rect and drawRect() draws event->rect(). They are drawn at mouse positions from mouseMoveEvent(). So I want to have app, where the circle, and square follow the cursor. I have such app but there is problem. The circle and square seem to be drawn at correct position, but they are clipped somehow. I've even enlarged the update rect by 100px but the clipping is still there. You can see it in the attached image. The code is below and also on the GitHub. I use Qt 5.15.1.

 void ScribbleArea::mouseMoveEvent(QMouseEvent *event)
{
        mousePos = event->pos();
        int enlargement = 100;
        int size = 129+enlargement;
        QRect r = QRect(mousePos.x()-size/2,mousePos.y()-size/2,size,size);
        update(r);
}

void ScribbleArea::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    
    int size = 129;
    QRect arcRect = QRect(mousePos.x()-size/2,mousePos.y()-size/2,size,size);
    
    painter.drawArc(arcRect,0,16*360);
    painter.drawRect(event->rect().adjusted(10,10,-10,-10));
}

The entire code is on GitHub: https://github.com/AlessandroFilipepi/QtDrawingExampleIssue (Don't worry, it is short).

Clipped brush

Thank for help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...