【问题标题】:Repaint not working in Graphics View重绘在图形视图中不起作用
【发布时间】:2014-08-16 02:32:10
【问题描述】:

我在图形视图中绘制时用于存储点。但是当我尝试多次添加线/点时,它不会被绘制。该点被存储,但绘画只完成一次。 我已经构建了多次绘制事物的信号。以下是代码: 点.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();
    }

【问题讨论】:

    标签: c++ qt


    【解决方案1】:

    当您使用图形视图时,您永远需要手动处理更新。图形视图代码中的任何手册update 都是错误,是设计从根本上被破坏的标志。你也不需要DrawFinished 信号。

    您需要并且唯一需要的是将相关的图元添加到场景中。就这样。所有更新等都将为您完成。这就是您使用图形视图而不是普通小部件的原因。如果您出于某种原因想要手动处理所有内容,则根本不需要图形视图。

    您可以查看完整示例 herehere。在这两种情况下,原语都是在运行时根据鼠标点击添加的。

    另请参阅 an example of animating graphics itemsand another oneexample of item selection

    所有示例都是独立的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多