最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pyqt5中動畫的使用詳解

 更新時間:2020年04月01日 14:53:30   作者:水痕001  
這篇文章主要介紹了pyqt5中動畫的使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

一、pyqt5中動畫的繼承關(guān)系圖

二、關(guān)于QAbstractAnimation父類的認識

1、主要作用

  • 繼承此類, 實現(xiàn)一些自定義動畫
  • 所有動畫共享的功能

2、功能作用

循環(huán)操作

  • setLoopCount(count):設(shè)置循環(huán)次數(shù)
  • currentLoop():當(dāng)前循環(huán)
  • currentLoopTime():當(dāng)前循環(huán)時間

時間操作

  • duration():單次時長
  • totalDuration():動畫總時長
  • currentTime():當(dāng)前時長

動畫方向

  • setDirection(QAbstractAnimation.Forward/QAbstractAnimation.Backward)

動畫狀態(tài)state()

  • QAbstractAnimation.Stopped:動畫停止
  • QAbstractAnimation.Paused:動畫暫停
  • QAbstractAnimation.Running:動畫運行

三、QPropertyAnimation屬性動畫的使用

主要用于實現(xiàn)某個屬性值從x到y(tǒng)的動畫變化

1、定義動畫的主要步驟

  • 創(chuàng)建一個動畫,并設(shè)置目標、屬性
  • 設(shè)置屬性值的開始、插值、結(jié)束
  • 動畫時長
  • 啟動動畫

2、構(gòu)造函數(shù)使用方式

1.QPropertyAnimation(parent: QObject = None)

  • 設(shè)置動畫目標:setTargetObject(self, QObject)
  • 設(shè)置動畫屬性(位置、大小等):setPropertyName(self, Union[QByteArray, bytes, bytearray])

2.QPropertyAnimation(QObject, Union[QByteArray, bytes, bytearray], parent: QObject = None)

3、常見的屬性

  • geometry
  • pos
  • size
  • windowOpacity

4、設(shè)置開始值和結(jié)束值

  • setStartValue(self, Any)
  • setEndValue(self, Any)
  • setKeyValueAt(self, float, Any)
  • setKeyValues(self, object)

5、設(shè)置動畫時長

  • setDuration(int mesc)

6、啟動動畫

  • start()

7、簡單案例(位置的)

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(100, 100)
    self.btn.move(0, 0)
    self.btn.setStyleSheet('QPushButton{border: none; background: pink;}')

    # 1.定義一個動畫
    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è)置時長
    animation.setDuration(3000)

    # 4.啟動動畫
    animation.start()


if __name__ == "__main__":
  app = QApplication(sys.argv)
  window = Window()
  window.show()
  sys.exit(app.exec_())

8、使用插值的動畫

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)建動畫
    animation = QPropertyAnimation(self.btn, b'pos', self)
    
    # 2.定義動畫插值
    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.動畫時長
    animation.setDuration(5000)
    # 4.啟動動畫
    animation.start()


if __name__ == "__main__":
  app = QApplication(sys.argv)
  window = Window()
  window.show()
  sys.exit(app.exec_())

四、QAnimationGroup動畫組的使用

可以將一組動畫, 同時播放或者按順序播放

1、使用的步驟

  • 根據(jù)上面的方式創(chuàng)建單獨的動畫(但不啟動)
  • 定義一個動畫組
  • 將之前的動畫添加到動畫組中
  • 啟動動畫組

2、動畫運行幾種狀態(tài)

  • 并行動畫QParallelAnimationGroup
  • 串行動畫QSequentialAnimationGroup

3、一個動畫組的案例

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.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的動畫
    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的動畫
    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_())

五、關(guān)于QAbstractAnimation中事件的操作

1、啟動動畫start()

2、暫停動畫pause()

3、繼續(xù)啟動動畫resume()

4、停止動畫stop()

5、基本案例

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.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的動畫
    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的動畫
    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中動畫的使用詳解的文章就介紹到這了,更多相關(guān)pyqt5 動畫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python中的unittest框架實例詳解

    python中的unittest框架實例詳解

    在本篇文章里小編給大家分享的是一篇關(guān)于python中的unittest框架實例詳解內(nèi)容,對此有興趣的朋友們可以學(xué)習(xí)下。
    2021-02-02
  • python與C、C++混編的四種方式(小結(jié))

    python與C、C++混編的四種方式(小結(jié))

    這篇文章主要介紹了python與C、C++混編的四種方式(小結(jié)),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • python pyinstaller 加載ui路徑方法

    python pyinstaller 加載ui路徑方法

    今天小編就為大家分享一篇python pyinstaller 加載ui路徑方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06
  • 關(guān)于Python?Tkinter?復(fù)選框?->Checkbutton

    關(guān)于Python?Tkinter?復(fù)選框?->Checkbutton

    這篇文章主要介紹了關(guān)于Python?Tkinter復(fù)選框Checkbutton,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-09-09
  • Python paramiko模塊使用解析(實現(xiàn)ssh)

    Python paramiko模塊使用解析(實現(xiàn)ssh)

    這篇文章主要介紹了Python paramiko模塊使用解析(實現(xiàn)ssh),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-08-08
  • python break和continue用法對比

    python break和continue用法對比

    在本篇文章里小編給大家整理的是一篇關(guān)于python break和continue用法對比內(nèi)容,有需要的朋友們可以學(xué)習(xí)參考下。
    2021-06-06
  • 用Python實現(xiàn)寫倒序輸出(任意位數(shù))

    用Python實現(xiàn)寫倒序輸出(任意位數(shù))

    這篇文章主要介紹了用Python實現(xiàn)寫倒序輸出(任意位數(shù)),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Python爬蟲之urllib基礎(chǔ)用法教程

    Python爬蟲之urllib基礎(chǔ)用法教程

    這篇文章主要為大家詳細介紹了Python爬蟲1.1 urllib基礎(chǔ)用法教程,用于對Python爬蟲技術(shù)進行系列文檔講解,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • python3+requests接口自動化session操作方法

    python3+requests接口自動化session操作方法

    今天小編就為大家分享一篇python3+requests接口自動化session操作方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • Python項目管理Git常用命令詳圖講解

    Python項目管理Git常用命令詳圖講解

    這篇文章主要介紹了Python項目管理Git常用命令詳圖講解,文中附含詳細的圖片講解,建議收藏閱讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2021-09-09

最新評論

南江县| 三门峡市| 离岛区| 井研县| 贵州省| 曲水县| 且末县| 玉林市| 连平县| 沁阳市| 阜平县| 手游| 米林县| 连平县| 嵊泗县| 邯郸市| 资中县| 阳泉市| 孟津县| 温泉县| 鄂伦春自治旗| 泰来县| 古交市| 奉新县| 黔南| 金溪县| 中方县| 察隅县| 清苑县| 屏南县| 伽师县| 循化| 名山县| 额敏县| 新河县| 荆门市| 田东县| 扶风县| 彭阳县| 新河县| 垣曲县|