右键菜单动画

This commit is contained in:
Irony 2018-08-22 17:59:13 +08:00
parent 180d11a7d1
commit cef020d4ec
5 changed files with 74 additions and 1 deletions

View file

@ -46,6 +46,7 @@ encoding//\u4EFFQQ\u8BBE\u7F6E\u9762\u677F/SettingUi.py=utf-8
encoding//\u4EFFQQ\u8BBE\u7F6E\u9762\u677F/Window.py=utf-8
encoding//\u5168\u5C40\u70ED\u952E/HotKey.py=utf-8
encoding//\u5206\u5272\u7A97\u53E3\u7684\u5206\u5272\u6761\u91CD\u5199/Splitter.py=utf-8
encoding//\u52A8\u753B\u7279\u6548/\u53F3\u952E\u83DC\u5355\u52A8\u753B.py=utf-8
encoding//\u52A8\u753B\u7279\u6548/\u6DE1\u5165\u6DE1\u51FA.py=utf-8
encoding//\u53F3\u4E0B\u89D2\u5F39\u51FA\u6846/WindowNotify.py=utf-8
encoding//\u56FE\u7247\u52A0\u8F7D/LoadImage.py=utf-8

View file

@ -75,6 +75,7 @@
### [5.动画特效](动画特效/)
- [5.1 淡入淡出](动画特效/淡入淡出.py)
- [5.2 右键菜单动画](动画特效/右键菜单动画.py)
### [6.QML](partner_625781186/QML_QtQuick_PY)

View file

@ -4,4 +4,7 @@
### 常见例子
- [1.1 淡入淡出](淡入淡出.py)<br/>
![截图](ScreenShot/1.gif)
![截图](ScreenShot/1.gif)
- [1.2 右键菜单动画](右键菜单动画.py)<br/>
![截图](ScreenShot/2.gif)

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View file

@ -0,0 +1,68 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年8月22日
@author: Irony
@site: https://github.com/892768447
@email: 892768447@qq.com
@file: 动画特效.右键菜单动画
@description:
"""
from PyQt5.QtCore import QPropertyAnimation, QEasingCurve, QRect
from PyQt5.QtWidgets import QWidget, QMenu, QApplication
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = "Copyright (c) 2018 Irony"
__Version__ = "Version 1.0"
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.resize(800, 600)
self.initMenu()
self.initAnimation()
def contextMenuEvent(self, event):
pos = event.globalPos()
size = self._contextMenu.sizeHint()
x, y, w, h = pos.x(), pos.y(), size.width(), size.height()
self._animation.stop()
self._animation.setStartValue(QRect(x, y, 0, 0))
self._animation.setEndValue(QRect(x, y, w, h))
self._animation.start()
self._contextMenu.exec_(event.globalPos())
def hello(self):
QApplication.instance().aboutQt()
def initAnimation(self):
# 按钮动画
self._animation = QPropertyAnimation(
self._contextMenu, b'geometry', self,
easingCurve=QEasingCurve.Linear, duration=300)
# easingCurve 修改该变量可以实现不同的效果
def initMenu(self):
self._contextMenu = QMenu(self)
self._contextMenu.addAction('菜单1', self.hello)
self._contextMenu.addAction('菜单2', self.hello)
self._contextMenu.addAction('菜单3', self.hello)
self._contextMenu.addAction('菜单4', self.hello)
self._contextMenu.addAction('菜单5', self.hello)
self._contextMenu.addAction('菜单6', self.hello)
if __name__ == '__main__':
import sys
import cgitb
sys.excepthook = cgitb.Hook(1, None, 5, sys.stderr, 'text')
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())