Nominate our 2022 Qt Champions!

Qt animated tiles example - question about QGraphics_

  • For anybody who doesn't know the code of the Qt4.7.4 animated tiles example:

    int main(int argc, char **argv)

    QApplication app(argc, argv);
    QPixmap kineticPix(":/images/kinetic.png");
    • QPixmap kineticPix_(":/images/kinetic_.png");*
      QPixmap bgPix(":/images/Time-For-Lunch-2.jpg");
    QGraphicsScene scene(-350, -350, 700, 700);
    QList<Pixmap *> items;
    for (int i = 0; i < 64; ++i) {

    *Pixmap item = NULL;
    if ( i % 2 == 1 )
    item = new Pixmap(kineticPix);
    } else
    item = new Pixmap(kineticPix_);

    item->setOffset(-kineticPix.width()/2, -kineticPix.height()/2);
    items << item;

    A few words to the changes. I have just changed the color of ":/images/kinetic.png" and I save this as ":/images/kinetic_.png".
    Then every even "Pixmap" should be the changed tile and every odd "Pixmap" should be the original tile. Then I compile this example.

    When execute the changed version of animated tiles all tiles look like the changed "Pixmap" ( ":/images/kinetic_.png")

    Here a picture:

    I have expected, that the tiles alternate.

    Is this a bug or which functions/method of QGraphics_ must I call to do, what I want?

    I embrace your answers.

    Bye Ecki

  • Edit your code, the * mean */ ?

  • And the solution is simply :) The image is not load, if you see the picture all is work! But the second image is not load! You see only 32 object of 64 :) The other 32 is 'hidden'.

  • Thanks. I fixed it.

Log in to reply