QGraphicsItem movement
-
Hi,
how can i remove the jerky movement effect when moving a QGraphicsItem?
the paltform is ubuntu 9.10 and this is the item code:
@ #include "asportowindow.h"AsportoWindow::AsportoWindow(MainScene *p,int w,int h,MysqlConnector2 *c,Logger2 *l) { logger=l; conn=c; width=w; height=h; parent=p; this->setParentItem(parent); setCacheMode(QGraphicsItem::DeviceCoordinateCache); movable=false; } void AsportoWindow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { painter->setPen(QPen(Qt::black, 0)); painter->setBrush(QColor(78,73,73)); painter->drawRect(0,0,width,height); } QRectF AsportoWindow::boundingRect() const { return QRectF(0,0,width,height); } QPainterPath AsportoWindow::shape() const { QPainterPath path; path.addRect(0,0,width,height); return path; } void AsportoWindow::mousePressEvent( QGraphicsSceneMouseEvent * event ) { startMovement=event->scenePos().x(); startX=this->scenePos().x(); startY=this->scenePos().y(); movable=true; lastCurrentX=startX; } void AsportoWindow::mouseReleaseEvent( QGraphicsSceneMouseEvent * event ) { endMovement=event->scenePos().x(); if(abs(currentMovement)<200) { setPos(0,startY); } else { setPos(startX,startY); } movable=false; } void AsportoWindow::mouseMoveEvent( QGraphicsSceneMouseEvent * event ) { currentMovement=event->scenePos().x(); if(currentMovement<startMovement) { //movememnt is right to left int delta=startMovement-currentMovement; lastCurrentX=currentX; currentX=startX-delta; width=width+delta; setPos(currentX,startY); } }
@
Thanks!