0

I am using to store the points while drawing in graphics view. But when I try to add the line/point multiple times it does not get painted. The point gets stored but the painting is done only once. I have the constructed the signals to draw the things multiple times. Following is the code: point.cpp

void point::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
    if(e->button()==Qt::LeftButton) {
        if(mClick){
            x1 = e->pos().x();
            y1 = e->pos().y();

            mClick = false;
            mPaintFlag = true;
            update();
            emit DrawFinished();//signal connected with the slot drawpoint() to paint the things mutiple times
        }
//storage
        _store.set_point(e->pos());
        store_point.push_back(_store);
        qDebug() << _store.getValue();
        qDebug() << "Size of vector =" << store_point.size() << "and" << store_point.capacity();
        update();
    }
user3877872
  • 809
  • 2
  • 9
  • 16

1 Answers1

0

When you're using a graphics view, you never need to handle updates manually. Any manual update in graphics view code is a bug, a sign of design that's fundamentally broken. You don't really need the DrawFinished signal either.

What you need, and the only thing you need, is to add the relevant primitives to the scene. That's all. All the updating etc. will be done for you. That's why you're using the graphics view and not a plain widget. If you want to handle everything manually for some reason, you don't need the graphics view at all.

You can see complete examples here and here. In both cases, primitives are added at runtime, based on mouse clicks.

See also an example of animating graphics items, and another one, and an example of item selection.

All examples are self-contained.

Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313