If you hold down the LMB and hold the mouse, you get a line, as it should be. This is the project itself: https://vk.com/doc66577607_445871169
This is the code snippet with the drawing itself:

void paintScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { addEllipse(event->scenePos().x() - brushSize, event->scenePos().y() - brushSize, (brushSize*2), (brushSize*2), pen, brush); previousPoint = event->scenePos(); } } void paintScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (event->buttons() == Qt::LeftButton) { addLine(previousPoint.x(), previousPoint.y(), event->scenePos().x(), event->scenePos().y(), QPen(color,brushSize*2,Qt::SolidLine,Qt::RoundCap)); previousPoint = event->scenePos(); } } 

UPD: figured out. In changeColor, I did not set the brush and pen colors. Thank.

Screen drawing

    1 answer 1

    In the addEllipse call addEllipse you use a black pen and / or brush .

    Why do you even draw something in mousePressEvent ?

    There, the color is set different.

    Where exactly? For the line every time you create a new pen with the color color . Do the same in addEllipse , and the dot will be blue:

     addEllipse(event->scenePos().x() - brushSize, event->scenePos().y() - brushSize, (brushSize*2), (brushSize*2), QPen(color,brushSize*2,Qt::SolidLine,Qt::RoundCap), brush); 

    And where does the paintEvent ? It's about drawing as a reaction to mouse movement.

    • There is a paintEvent for drawing. - Vanyamba Electronics
    • There, the color is set different. If black were, then the line would be black. - scarletchaos
    • Thanks for the paintEvent. - scarletchaos
    • In the paintScene constructor: puu.sh/w0z0V/62aaed644f.png . It sets the default color. Then you can change it through paintScene :: changeColor. But whichever you set by default and on which you change, the dots are still black - scarletchaos
    • @scarletchaos - are you talking to me? I continue to insist on my answer. - Igor