官术网_书友最值得收藏!

How it works...

One of the more common methods to animate a GUI element is through the property animation class provided by Qt, known as the QPropertyAnimation class. This class is part of the animation framework and it makes use of the timer system in Qt to change the properties of a GUI element over a given duration.

What we are trying to accomplish here is to animate the button from one position to another while, at the same time, enlarging the button size along the way. By including the QPropertyAnimation header in our source code in step 2, we will be able to access the QPropertyAnimation class provided by Qt and make use of its functionalities.

The code in step 3 basically creates a new property animation and applies it to the push button we just created in Qt Designer. We specifically request that the property animation class changes the geometry properties of the push button and sets its duration to 3,000 milliseconds (3 seconds).

Then, the start value of the animation is set to the initial geometry of the push button because, obviously, we want it to start from where we initially place the button in Qt Designer. The end value is then set to what we want it to become; in this case, we will move the button to a new position at x: 200 and y: 200 while changing its size to width: 100 and height: 50 along the way.

After that, call animation | start() to start the animation. Compile and run the project. You should see the button start to move slowly across the main window while expanding in size a bit at a time, until it reaches its destination. You can change the animation duration and the target position and scale by altering the values in the preceding code. It is really that simple to animate a GUI element using Qt's property animation system!

主站蜘蛛池模板: 乐陵市| 东乡| 凭祥市| 五莲县| 华容县| 上虞市| 清水县| 益阳市| 盐津县| 修水县| 凯里市| 蒙自县| 花莲市| 同江市| 玉山县| 大冶市| 江西省| 郧西县| 科技| 砚山县| 尼玛县| 岑溪市| 溆浦县| 沈丘县| 资阳市| 邹城市| 漳浦县| 化德县| 且末县| 外汇| 象山县| 台州市| 淮北市| 公安县| 崇仁县| 白城市| 青龙| 广平县| 北宁市| 罗平县| 秭归县|