Important: Please read the Qt Code of Conduct -

How to set a moving background (images) into my QWidget

  • Hello everyone, I am relatively new to Qt Creator C++, and I would like to create a windows program (just a QWidget window) where the background is constantly moving from right to left. I found the perfect picture on the internet to illustrate what I mean:
    [logo]: "Phone image"

    I have thought about ways to do it, and I think I I should first create my own separate images, such the Sun, different clouds, and the buildings and then add them into my QWidget. Now my problem is how to make the clouds and buildings move recurrently (after a cloud has disappeared on the left, it appears again on the right) while the Sun stays stationary. I have no idea how to do this, but I guess I should start by creating a QGraphicsScene ? Or should I first learn Qt Quick ?

    Thank you for your help !

  • Lifetime Qt Champion

    hi and welcome
    Qt Quick/QML would be good for such animation
    but its also important to consider what rest of application should do.
    Is it a normal desktop program or more like a phone app ?

    QGraphicsScene could also work really well.

    So I would choose QML or QGraphicsScene based upon what else the app needs to do.

  • If it requires user interaction QML is probably the faster way, otherwise make the image a .gif use a QLabel as base and use setMovie() to load the gif (remember to start the movie)

  • @mrjj Hello, thank you for your quick answer. Well, first I would like to create a desktop program and consider a phone app later. I think I'll start by learning QML/Qt Quick then, as I've seen that the Qt Quick demo - Maroon in trouble is pretty much close to what I want to do

  • @VRonin
    Oh yeah, I didn't think about a .gif ! That will spare me the complication of trying to find a way to make the scene recurrent. Thank you !