Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person

Categories

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.


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

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...