我在绘制图形视图时用来存储点。但是当我尝试多次添加线/点时,它不会被绘制。该点被存储,但绘画只进行一次。 我已经构造了信号来多次绘制东西。以下是代码: 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();
}
答案 0 :(得分:0)
当您使用图形视图时,永远不会需要手动处理更新。图形视图代码中的任何手动update
都是一个错误,是设计从根本上打破的标志。您也不需要DrawFinished
信号。
您需要的,唯一需要的是将相关的基元添加到场景中。这就是全部。所有的更新等都将为您完成。这就是您使用图形视图而不是普通小部件的原因。如果您想出于某种原因手动处理所有内容,则根本不需要图形视图。
您可以看到完整的示例here和here。在这两种情况下,基于鼠标点击,在运行时添加基元。
另请参阅an example of animating graphics items,and another one和example of item selection。
所有示例都是自包含的。