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. QPropertyAnimation of a QGraphicsTextItem with a frame make the text shaky

QPropertyAnimation of a QGraphicsTextItem with a frame make the text shaky

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 437 Views
  • 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.
  • P Offline
    P Offline
    plover
    wrote on last edited by plover
    #1

    I'm animating a QGraphicsTextItem that I've added a frame around. During the animation the text seems to shake slightly inside the frame, which is very annoying.

    An example code:

    class MovingFrameText : public QGraphicsTextItem
    {
       Q_OBJECT;
      public:
         MovingFrameText( ): QGraphicsTextItem(0)
         {
            setPlainText ( "Shaky ");
            QFont f =  font();
            f.setPixelSize(40);
            setFont(f);
            setFlags(QGraphicsItem::ItemIsMovable);
         }
    
         QRectF boundingRect() const
         {
            return QGraphicsTextItem::boundingRect().adjusted(-2,-2,+2,+2);
         }
    
         void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
         {
            QGraphicsTextItem::paint(painter,option,widget);
            painter->setPen(Qt::black);
            painter->drawRect(boundingRect());
         }
    
    };
    
    int main(int argc, char *argv[])
    {
      QApplication app(argc,argv);
    
      MovingFrameText t;
      t.setPos(640,680);
    
      QGraphicsScene scene;
      scene.addItem(&t);
    
      QGraphicsView view(&scene);
      view.resize(640, 680);
      view.show();
    
      auto moveAnimation = new QPropertyAnimation( &t,  "pos" );
      moveAnimation->setDuration( 10000 );
      moveAnimation->setStartValue( QPointF(640, 680) );
      moveAnimation->setEndValue(  QPointF(0, 0) );
      moveAnimation->setEasingCurve( QEasingCurve::Linear );
      moveAnimation->start(QAbstractAnimation::DeleteWhenStopped);
    
      return app.exec();
    }
    

    Is there any way to fix this and make the animation smooth? I've tried to find a solution online for some time now, and I can't seem to find any.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      plover
      wrote on last edited by
      #2

      Two decent solutions at: https://stackoverflow.com/questions/52853322/qpropertyanimation-of-a-qgraphicstextitem-with-a-frame-make-the-text-shaky

      1 Reply Last reply
      2

      • Login

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