PyQt5 Creating Animation with QPropertyAnimation

In this PyQt5 article i want to show you Creating Animation with QPropertyAnimation. so first of all let’s talk about QPropertyAnimation.

 

 

What is QPropertyAnimation?

QPropertyAnimation class animates Qt properties. QPropertyAnimation interpolates over Qt properties. this class inherits QVariantAnimation, and supports animation of the same meta types as its super class. A class declaring properties must be a QObject. To make it possible to animate a property, it must provide a setter (so that QPropertyAnimation can set the property’s value). Note that this makes it possible to animate many of Qt’s widgets.

 

 

 

This is the complete code for this article

 

 

 

In here we are going to create our main Window class that extends from QMainWindow. and in the constructor of the class we need to add some requirements of the window like set window title, window icon and window geometry.

 

 

 

 

In the InitWindow() method we set our window title, window icon and window geometry, also we create a button and a frame in this method.

 

 

 

These lines of codes are for button creation also you can see that we have connected doAnimation() slot or method with clicked signal of button.

 

 

This is our Frame creation.

 

 

 

And this method is for creating Animation in PyQt5, in the first we have created the object of QPropertyAnimation. after that we have created the duration for our Animation and at the end we have started the animation.

 

 

 

 

So run the code and this will be the result.

PyQt5 Creating Animation with QPropertyAnimation
PyQt5 Creating Animation with QPropertyAnimation

 

 

FAQs:

 

What is QPropertyAnimation in PyQt5?

QPropertyAnimation class animates Qt properties. QPropertyAnimation interpolates over Qt properties. this class inherits QVariantAnimation, and supports animation of the same meta types as its super class. A class declaring properties must be a QObject. To make it possible to animate a property, it must provide a setter (so that QPropertyAnimation can set the property’s value). Note that this makes it possible to animate many of Qt’s widgets.

 

 

What are the key features of the Window class in PyQt5?

Window class extends QMainWindow and initializes window properties such as title, icon, and geometry. It also contains a method called InitWindow() where the window title, icon, geometry, button and frame are set up.

 

 

How is the frame created?

The frame is created using QFrame. Its style is set to QFrame.Panel | QFrame.Raised, and its geometry is set using the setGeometry() method.

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×