PDA

View Full Version : QGraphicsView scroll problem or retained image on screen



chinghungpan
31st October 2014, 15:42
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):
QGraphicsView(parent)

{
m_qGraphicsScene = new QGraphicsScene;
setScene(m_qGraphicsScene);
//selection box
m_pGRecItemSelectionBox=new QGraphicsRectItem();
m_qGraphicsScene->addItem(m_pGRecItemSelectionBox);
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()));
m_pGRecItemSelectionBox->show();
}

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));
m_pGRecItemSelectionBox->setPen(QPen(Qt::NoPen));

}
void ggraphicsView::mouseReleaseEvent( QMouseEvent* event)
{
m_pGRecItemSelectionBox->hide();
}

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

stampede
31st October 2014, 22:28
I don't know what you are trying to do, but maybe try calling QGraphicsScene::update() at the end of move and release handlers.

chinghungpan
2nd November 2014, 07:08
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.

wysota
2nd November 2014, 11:55
You always use some viewport update mode :) Maybe you disabled automatic updates.