Snowflakes effect with Qt

Its Christmas time so its snowflakes time.  Just before this weekend I tried snowflakes effect using Qt. The basic idea is to get snowflakes falling through your desktop from random points. In short, a transparent graphics view is created with the desktop size so that it covers entire desktop. Each snowflake is a QGraphicsPixmapItem which is encapsulated in a QGraphicsWidget. Now each snowflake’s position property (i.e., QGraphicsWidget’s “pos” property) is animated using a QPropertyAnimation.  Each snowflake starts falling from a random position within the width of the screen; this position serves as starting point of the animation and a position at bottom of screen is end point. To get a realistic wind effect, the end point is not straight but added or subtracted with an offset so that snowflake falls down with an angle. A timer is started and a new snowflake is created and animated in its timeout and the cumulative effect  after a few seconds is snowfall! With Qt’s powerful animation framework, it took not more than 2 hours to finish the job. Feel free to grab the code from my usual repo

Please mind that there is some problem when running it on linux as the widget flags combination is not working as expected.

snowflakes running on my desktop

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s