Important: Please read the Qt Code of Conduct -

QGraphicsView scroll problem or retained image on screen

  • Please Help me!!! And sorry about my poor English.
    I add QGraphicsRectItem in QGraphicsScene, and set very large SceneRect. QGraphicsView show scroller up.
    When mouse press , move on QGraphicsScene, I will do QGraphicsRectItem->setRect() .
    When mouse release will hide QGraphicsRectItem.
    when I move mouse and scroller , some time mouse release will have some retained image on QGraphicsView

    my code:
    ggraphicsView::ggraphicsView(QWidget *parent):

    m_qGraphicsScene = new QGraphicsScene;
    //selection box
    m_pGRecItemSelectionBox=new QGraphicsRectItem();
    m_qGraphicsScene->setSceneRect(QRectF(0,0, 600,1000));

    void ggraphicsView::mousePressEvent( QMouseEvent* event)
    m_ptStartPoint = mapToScene(event->pos());
    m_pGRecItemSelectionBox->setRect(QRectF(m_ptStartPoint, QSize()));

    void ggraphicsView::mouseMoveEvent (QMouseEvent* event)
    m_ptMovePoint = mapToScene(event->pos());
    m_pGRecItemSelectionBox->setRect(QRectF(m_ptStartPoint, m_ptMovePoint).normalized());
    m_pGRecItemSelectionBox->setBrush(QBrush(QColor(128, 128, 255, 100),Qt::SolidPattern));

    void ggraphicsView::mouseReleaseEvent( QMouseEvent* event)

    problem: retained image ,when mouse move & wheel together.
    ! image)!

    [edit: added missing coding tags @ SGaist]

  • it is weird, i answer my question.
    this quest I try to do QRubberBand.
    mouse press and move show a Rectangle, mouse release will disappear.

    It is about viewport update. if someone have same problem, u can see QGraphicsView::ViewportUpdateMode.

Log in to reply