- Qt5 C++ GUI Programming Cookbook
- Lee Zhi Eng
- 323字
- 2021-07-02 12:17:59
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!
- 床旁超聲監(jiān)測
- 復(fù)發(fā)性口腔潰瘍中西醫(yī)結(jié)合診斷和治療
- 新編男性不育與不孕
- 慢性胃炎百家百方
- 角膜塑形鏡驗(yàn)配技術(shù)基礎(chǔ)篇
- Building RESTful Web Services with Java EE 8
- 臨床檢驗(yàn)一萬個為什么:病原檢驗(yàn)分冊
- 癲癇的診斷與治療:臨床實(shí)踐與思考
- 臨床X線頭影測量學(xué)(第2版)
- 圖說災(zāi)難逃生自救叢書:海嘯
- 分?jǐn)?shù)階微積分圖像修復(fù)模型在醫(yī)學(xué)CT圖像金屬偽影去除中的應(yīng)用
- 不可逆電穿孔消融技術(shù)的應(yīng)用原理與實(shí)踐
- 會診聯(lián)絡(luò)精神醫(yī)學(xué)
- 會保養(yǎng)的女人年輕20歲
- 與癌共舞