您好,登錄后才能下訂單哦!
1、主要作用
2、功能作用
循環(huán)操作
時(shí)間操作
動(dòng)畫方向
動(dòng)畫狀態(tài)state()
主要用于實(shí)現(xiàn)某個(gè)屬性值從x到y(tǒng)的動(dòng)畫變化
1、定義動(dòng)畫的主要步驟
2、構(gòu)造函數(shù)使用方式
1.QPropertyAnimation(parent: QObject = None)
2.QPropertyAnimation(QObject, Union[QByteArray, bytes, bytearray], parent: QObject = None)
3、常見的屬性
4、設(shè)置開始值和結(jié)束值
5、設(shè)置動(dòng)畫時(shí)長
6、啟動(dòng)動(dòng)畫
7、簡單案例(位置的)
import sys from PyQt5.Qt import * class Window(QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('動(dòng)畫') self.resize(500, 500) self.move(400, 200) self.btn = QPushButton(self) self.init_ui() def init_ui(self): self.btn.resize(100, 100) self.btn.move(0, 0) self.btn.setStyleSheet('QPushButton{border: none; background: pink;}') # 1.定義一個(gè)動(dòng)畫 animation = QPropertyAnimation(self) animation.setTargetObject(self.btn) animation.setPropertyName(b'pos') # 使用另外一種構(gòu)造函數(shù)方式創(chuàng)建 # animation = QPropertyAnimation(self.btn, b'pos', self) # 2.設(shè)置屬性值 animation.setStartValue(QPoint(0, 0)) animation.setEndValue(QPoint(400, 400)) # 3.設(shè)置時(shí)長 animation.setDuration(3000) # 4.啟動(dòng)動(dòng)畫 animation.start() if __name__ == "__main__": app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
8、使用插值的動(dòng)畫
import sys from PyQt5.Qt import * class Window(QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('使用插值') self.resize(500, 500) self.move(400, 200) self.btn = QPushButton(self) self.init_ui() def init_ui(self): self.btn.resize(50, 50) self.btn.move(0, 0) self.btn.setStyleSheet('QPushButton{border: none; background: pink;}') # 1.創(chuàng)建動(dòng)畫 animation = QPropertyAnimation(self.btn, b'pos', self) # 2.定義動(dòng)畫插值 animation.setKeyValueAt(0, QPoint(0, 0)) animation.setKeyValueAt(0.25, QPoint(450, 0)) animation.setKeyValueAt(0.5, QPoint(450, 450)) animation.setKeyValueAt(0.75, QPoint(0, 450)) animation.setKeyValueAt(1, QPoint(0, 0)) # 3.動(dòng)畫時(shí)長 animation.setDuration(5000) # 4.啟動(dòng)動(dòng)畫 animation.start() if __name__ == "__main__": app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
可以將一組動(dòng)畫, 同時(shí)播放或者按順序播放
1、使用的步驟
2、動(dòng)畫運(yùn)行幾種狀態(tài)
3、一個(gè)動(dòng)畫組的案例
import sys from PyQt5.Qt import * class Window(QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('動(dòng)畫組') self.resize(500, 500) self.move(400, 200) self.btn1 = QPushButton(self) self.btn2 = QPushButton(self) self.init_ui() def init_ui(self): self.btn1.resize(50, 50) self.btn1.move(0, 0) self.btn1.setStyleSheet('QPushButton{border: none; background: pink;}') self.btn2.resize(50, 50) self.btn2.move(50, 50) self.btn2.setStyleSheet('border: none; background: cyan') # 按鈕1的動(dòng)畫 animation1 = QPropertyAnimation(self.btn1, b'pos', self) animation1.setKeyValueAt(0, QPoint(0, 0)) animation1.setKeyValueAt(0.25, QPoint(450, 0)) animation1.setKeyValueAt(0.5, QPoint(450, 450)) animation1.setKeyValueAt(0.75, QPoint(0, 450)) animation1.setKeyValueAt(1, QPoint(0, 0)) animation1.setDuration(5000) # animation1.start() # 按鈕2的動(dòng)畫 animation2 = QPropertyAnimation(self.btn2, b'pos', self) animation2.setKeyValueAt(0, QPoint(50, 50)) animation2.setKeyValueAt(0.25, QPoint(400, 50)) animation2.setKeyValueAt(0.5, QPoint(400, 400)) animation2.setKeyValueAt(0.75, QPoint(50, 400)) animation2.setKeyValueAt(1, QPoint(50, 50)) animation2.setDuration(3000) # animation2.start() animation_group = QSequentialAnimationGroup(self) animation_group.addAnimation(animation1) animation_group.addAnimation(animation2) animation_group.start() if __name__ == "__main__": app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
1、啟動(dòng)動(dòng)畫start()
2、暫停動(dòng)畫pause()
3、繼續(xù)啟動(dòng)動(dòng)畫resume()
4、停止動(dòng)畫stop()
5、基本案例
import sys from PyQt5.Qt import * class Window(QWidget): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setWindowTitle('動(dòng)畫組') self.resize(500, 500) self.move(400, 200) self.btn1 = QPushButton(self) self.btn2 = QPushButton(self) self.init_ui() def init_ui(self): self.btn1.resize(50, 50) self.btn1.move(0, 0) self.btn1.setStyleSheet('QPushButton{border: none; background: pink;}') self.btn2.resize(50, 50) self.btn2.move(50, 50) self.btn2.setStyleSheet('border: none; background: cyan') # 按鈕1的動(dòng)畫 animation1 = QPropertyAnimation(self.btn1, b'pos', self) animation1.setKeyValueAt(0, QPoint(0, 0)) animation1.setKeyValueAt(0.25, QPoint(450, 0)) animation1.setKeyValueAt(0.5, QPoint(450, 450)) animation1.setKeyValueAt(0.75, QPoint(0, 450)) animation1.setKeyValueAt(1, QPoint(0, 0)) animation1.setDuration(5000) # animation1.start() # 按鈕2的動(dòng)畫 animation2 = QPropertyAnimation(self.btn2, b'pos', self) animation2.setKeyValueAt(0, QPoint(50, 50)) animation2.setKeyValueAt(0.25, QPoint(400, 50)) animation2.setKeyValueAt(0.5, QPoint(400, 400)) animation2.setKeyValueAt(0.75, QPoint(50, 400)) animation2.setKeyValueAt(1, QPoint(50, 50)) animation2.setDuration(8000) # animation2.start() animation_group = QParallelAnimationGroup(self) animation_group.addAnimation(animation1) animation_group.addAnimation(animation2) animation_group.start() self.btn1.clicked.connect(animation_group.pause) self.btn2.clicked.connect(animation_group.resume) if __name__ == "__main__": app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
到此這篇關(guān)于pyqt5中動(dòng)畫的使用詳解的文章就介紹到這了,更多相關(guān)pyqt5 動(dòng)畫內(nèi)容請搜索億速云以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持億速云!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。