Qt-interest Archive, September 2007
move qgraphicsitem move and borders
Message 1 in thread
I have problem with graphics scene, it's about moving items on graphics
scene. I have my own widgets that inherit after qgraphicsrectitem. They
have own function void mouseMoveEvent ( QGraphicsSceneMouseEvent *
event
); . The point is they should restrict parent sceneboundingrect when
they
are moving by mouse. So if widget have no parents it should be not
possible to move it to the left more then left border of canvas (sorry
for
my english). This restrict is own for parents. If there is parent it
should be not possible to move it from parents borders.
In my widget this looks like this:
void CanvasItemRectangle::mouseMoveEvent ( QGraphicsSceneMouseEvent *
event ) {
QGraphicsItem * _parent = parentItem(); QRectF wymiar ;
wymiar = sceneBoundingRect();
(...)
QPointF lpoint = event->lastPos();
QPointF point = event->pos();
if (_parent) {
wymiar0=_parent->sceneBoundingRect(); qreal _x;
qreal _y;
_x = point.x() - lpoint.x() ;
_y = point.y() - lpoint.y() ;
// for crossing left border
if (wymiar0.x() > wymiar.x() + _x){
//here code for setRect() or pos()
}
(...)
QgraphicsItem::mouseMoveEvent(event);
}
The problem is that when i move item and border of parent occurs items
is
flickering. I think it's because one is putting setRect or pos and
second
is that recognize of that the mouse already cross line is build on
sceneevent, and lasPos in event wasn't changed.
I was try to solve this problem for loooong time, so I want to please
you
for help
Best regards.