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. Animate objects from QList ( Using QTimer )
QtWS25 Last Chance

Animate objects from QList ( Using QTimer )

Scheduled Pinned Locked Moved General and Desktop
qlistqwidgetqpainterqtimer
2 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    Afterwork
    wrote on 5 Apr 2015, 18:28 last edited by Afterwork 4 May 2015, 18:31
    #1

    Hi everyone ! I have the QList of object which i paint in paintEvent . I am using State pattern (States: Loading,Menu) . Game is singleton , current is pointer class State *current, and GameWidget (inherited from QWidget) I use to draw the objects.
    There is paintEvent :

    void GameWidget::paintEvent(QPaintEvent *)
    {
       foreach(const Object& obj,Game::Instance().current->objects())
        {
            QPainter painter(this);
            painter.drawPixmap(obj.point,QPixmap(obj.pixmap));
        }
    }
    

    This is function from Loading state :

    QList <Object> Loading::objects()
    {
        QList <Object> objects;
        objects.append( Object(3,3,":/images/one.jpeg") );
        objects.append( Object(300,300,":/images/one.jpeg") );
        return objects;
    }
    

    and this is Object class for creating new objects to append in QList :

    class Object
    {
    public:
        QPoint point;
        QPixmap pixmap;
        Object(int x,int y, QString load)
        {
            point+= QPoint(x,y);
            pixmap.load(load);
        }
    };
    

    Question : How animate object ( using QTimer ) ? For example I want the first object move from ( 3 , 3 ) to (100,100) for 5 seconds.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Apr 2015, 20:43 last edited by
      #2

      Hi,

      You can use the Animation Framework for that. But rather than painting on a widget since you seem to be writing a game, you should take a look at the GraphicsView Framework

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      2/2

      5 Apr 2015, 20:43

      • Login

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