PDA

View Full Version : QGraphicsRectItem in FullScreen mode, when mouse dragging, blinking



stella1016
29th March 2011, 11:52
I have drawn QGraphicsItem in scene, and these QGraphicsItem have children(QGraphicsRectItem) above it as well.

My program provides the mouse action to resize or move the child items. During mouse dragging, if I drag the right-side edge of the rect to left side, which makes the rect invalid (minus width), the paiting of the rect starts blinking. It paints only during mouse-move, which means, if I stop moving the mouse but pressing the mouse, it will not show up. But if I release mouse, it shows correctly. This problem only happends in FullScreen mode, in normal window mode, no such problem.

I guess this comes from the zvalue of items. I set the parent zvalue: normal mode 2.0, Fullscreen mode 1.0. Child item is always 2.5.
To my knowledge, this makes sure the child item will be above the parent item, then I can easily grasp it. But I don't know what happens for the paiting in fullscreen mode.

Any one can give me a hint? Thanks.

MarekR22
29th March 2011, 13:23
I guess (you didn't show any code) that when object resizes (boundingRect changes) you forgot to call QGraphicsItem::prepareGeometryChange!

stella1016
30th March 2011, 09:41
I guess (you didn't show any code) that when object resizes (boundingRect changes) you forgot to call QGraphicsItem::prepareGeometryChange!

I do call prepareGeometryChange() when I setRect() in child item (QGraphicsRectItem) inside mouseMoveEvent.

I get some progress. I found, if in resizeEvent of QGraphicsView, code I has the blinking problem, code II doesn't. I am confused why this can cause such effect. resizeEvent is called only once when going to FullScreen mode, and never reached afterwards when I drag the edge of childItem. I can post the code of the resizeEvent:

code I:


void my_graphicsView::resizeEvent(QResizeEvent *event)
{
setWidth(event->size().width());
setHeight(event->size().height());

fitInView(QRectF(0,0,width(),height()),Qt::KeepAsp ectRatioByExpanding);
arrangeNodes();

m_scene->setSceneRect(0,0,width(),height());
this->setSceneRect(0,0,width(),height());

update();
}


code II:


void my_graphicsView::resizeEvent(QResizeEvent *event)
{
setWidth(event->size().width());
setHeight(event->size().height());

fitInView(QRectF(0,0,width(),height()),Qt::KeepAsp ectRatioByExpanding);
arrangeNodes();

m_scene->update(0,0,width(),height());
update();
}

high_flyer
30th March 2011, 19:47
I am not sure what the logic of calling QGrphicsViewe::update() is, it will update the whole visible (maybe even the not visible part, I am not sure) scene as well.
Why not just call updateScene()?