Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsItem movement
Forum Updated to NodeBB v4.3 + New Features

QGraphicsItem movement

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 687 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    azi021
    wrote on last edited by
    #1

    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!

    http://futsaliha.mihanblog.com
    http://soccerdl.mihanblog.com
    www.educationchess.blogfa.com
    www.skatetraining.blogfa.com
    www.bodybuilders.persianblo...

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved