[Qt-interest] QGraphicsItem jerky movement
Riccardo Roasio
riccardo.roasio at gmail.com
Fri Jul 16 12:44:58 CEST 2010
Hi,
you are right..
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);
}
}
2010/7/16 Andre Somers <andre at familiesomers.nl>:
> Op 16-7-2010 10:33, Riccardo Roasio schreef:
>> Hi,
>>
>> how can i remove the jerky movement effect when moving a QGraphicsItem?
>>
>> Thanks,
>> Riccardo
>> _______________________________________________
>>
> Did you forget to chant the magic incantations for smooth movements? Qt
> responds very well to charms and other forms of magic, I am told...
>
> Or, perhaps more helpful: we mere mortal programmers don't have crystal
> balls that show us your code. You should provide enough information for
> us to help you, such as what it is you are trying to do, on what
> platform, using what (relevant) code, and preferably a link to a small,
> self-contained example that demonstrates the issue.
>
> André
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list