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

PyQt5實現(xiàn)平滑移動側(cè)邊菜單欄效果的示例

 更新時間:2025年05月14日 10:58:40   作者:JHC000000  
本文主要介紹了PyQt5實現(xiàn)平滑移動側(cè)邊菜單欄效果的示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

CDrawer.py

#!/usr/bin/env python
# encoding: utf-8
'''
@author: JHC 
@license: None
@contact: JHC000abc@gmail.com
@file: CDrawer.py
@time: 2022/07/19/ 16:56
@desc:
'''
from PyQt5.QtCore import Qt, QPropertyAnimation, QEasingCurve, QPoint, QPointF
from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import QWidget, QApplication

class CDrawer(QWidget):

    LEFT, TOP, RIGHT, BOTTOM = range(4)

    def __init__(self, *args, stretch=1 / 3, direction=0, widget=None, **kwargs):
        super(CDrawer, self).__init__(*args, **kwargs)
        self.setWindowFlags(self.windowFlags(
        ) | Qt.FramelessWindowHint | Qt.Popup | Qt.NoDropShadowWindowHint)
        self.setAttribute(Qt.WA_StyledBackground, True)
        self.setAttribute(Qt.WA_TranslucentBackground, True)
        # 進入動畫
        self.animIn = QPropertyAnimation(
            self, duration=500, easingCurve=QEasingCurve.OutCubic)
        self.animIn.setPropertyName(b'pos')
        # 離開動畫
        self.animOut = QPropertyAnimation(
            self, duration=500, finished=self.onAnimOutEnd,
            easingCurve=QEasingCurve.OutCubic)
        self.animOut.setPropertyName(b'pos')
        self.animOut.setDuration(500)
        self.setStretch(stretch)        # 占比
        self.direction = direction      # 方向
        # 半透明背景
        self.alphaWidget = QWidget(
            self, objectName='CDrawer_alphaWidget',
            styleSheet='#CDrawer_alphaWidget{background:rgba(55,55,55,100);}')
        self.alphaWidget.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.setWidget(widget)          # 子控件

    def resizeEvent(self, event):
        self.alphaWidget.resize(self.size())
        super(CDrawer, self).resizeEvent(event)

    def mousePressEvent(self, event):
        pos = event.pos()
        if pos.x() >= 0 and pos.y() >= 0 and self.childAt(pos) == None and self.widget:
            if not self.widget.geometry().contains(pos):
                self.animationOut()
                return
        super(CDrawer, self).mousePressEvent(event)

    def show(self):
        super(CDrawer, self).show()
        parent = self.parent().window() if self.parent() else self.window()
        if not parent or not self.widget:
            return
        # 設(shè)置Drawer大小和主窗口一致
        self.setGeometry(parent.geometry())
        geometry = self.geometry()
        self.animationIn(geometry)

    def animationIn(self, geometry):
        """進入動畫
        :param geometry:
        """
        if self.direction == self.LEFT:
            # 左側(cè)抽屜
            self.widget.setGeometry(
                0, 0, int(geometry.width() * self.stretch), geometry.height())
            self.widget.hide()
            self.animIn.setStartValue(QPoint(-self.widget.width(), 0))
            self.animIn.setEndValue(QPoint(0, 0))
            self.animIn.start()
            self.widget.show()
        elif self.direction == self.TOP:
            # 上方抽屜
            self.widget.setGeometry(
                0, 0, geometry.width(), int(geometry.height() * self.stretch))
            self.widget.hide()
            self.animIn.setStartValue(QPoint(0, -self.widget.height()))
            self.animIn.setEndValue(QPoint(0, 0))
            self.animIn.start()
            self.widget.show()
        elif self.direction == self.RIGHT:
            # 右側(cè)抽屜
            width = int(geometry.width() * self.stretch)
            self.widget.setGeometry(
                geometry.width() - width, 0, width, geometry.height())
            self.widget.hide()
            self.animIn.setStartValue(QPoint(self.width(), 0))
            self.animIn.setEndValue(
                QPoint(self.width() - self.widget.width(), 0))
            self.animIn.start()
            self.widget.show()
        elif self.direction == self.BOTTOM:
            # 下方抽屜
            height = int(geometry.height() * self.stretch)
            self.widget.setGeometry(
                0, geometry.height() - height, geometry.width(), height)
            self.widget.hide()
            self.animIn.setStartValue(QPoint(0, self.height()))
            self.animIn.setEndValue(
                QPoint(0, self.height() - self.widget.height()))
            self.animIn.start()
            self.widget.show()

    def animationOut(self):
        """離開動畫
        """
        self.animIn.stop()  # 停止進入動畫
        geometry = self.widget.geometry()
        if self.direction == self.LEFT:
            # 左側(cè)抽屜
            self.animOut.setStartValue(geometry.topLeft())
            self.animOut.setEndValue(QPoint(-self.widget.width(), 0))
            self.animOut.start()
        elif self.direction == self.TOP:
            # 上方抽屜
            self.animOut.setStartValue(QPoint(0, geometry.y()))
            self.animOut.setEndValue(QPoint(0, -self.widget.height()))
            self.animOut.start()
        elif self.direction == self.RIGHT:
            # 右側(cè)抽屜
            self.animOut.setStartValue(QPoint(geometry.x(), 0))
            self.animOut.setEndValue(QPoint(self.width(), 0))
            self.animOut.start()
        elif self.direction == self.BOTTOM:
            # 下方抽屜
            self.animOut.setStartValue(QPoint(0, geometry.y()))
            self.animOut.setEndValue(QPoint(0, self.height()))
            self.animOut.start()

    def onAnimOutEnd(self):
        """離開動畫結(jié)束
        """
        # 模擬點擊外側(cè)關(guān)閉
        QApplication.sendEvent(self, QMouseEvent(
            QMouseEvent.MouseButtonPress, QPointF(-1, -1), Qt.LeftButton, Qt.NoButton, Qt.NoModifier))

    def setWidget(self, widget):
        """設(shè)置子控件
        :param widget:
        """
        self.widget = widget
        if widget:
            widget.setParent(self)
            self.animIn.setTargetObject(widget)
            self.animOut.setTargetObject(widget)

    def setEasingCurve(self, easingCurve):
        """設(shè)置動畫曲線
        :param easingCurve:
        """
        self.animIn.setEasingCurve(easingCurve)

    def getStretch(self):
        """獲取占比
        """
        return self.stretch

    def setStretch(self, stretch):
        """設(shè)置占比
        :param stretch:
        """
        self.stretch = max(0.1, min(stretch, 0.9))

    def getDirection(self):
        """獲取方向
        """
        return self.direction

    def setDirection(self, direction):
        """設(shè)置方向
        :param direction:
        """
        direction = int(direction)
        if direction < 0 or direction > 3:
            direction = self.LEFT
        self.direction = direction

Qt.py

#!/usr/bin/env python
# encoding: utf-8
'''
@author: JHC 
@license: None
@contact: JHC000abc@gmail.com
@file: QT.py
@time: 2022/07/19/ 16:53
@desc:
'''
from PyQt5.QtCore import Qt
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from CDrawer import CDrawer
import sys
import cgitb
sys.excepthook = cgitb.enable(1, None, 5, '')
from PyQt5.QtWidgets import QApplication


class DrawerWidget(QWidget):

    def __init__(self, *args, **kwargs):
        super(DrawerWidget, self).__init__(*args, **kwargs)
        self.setAttribute(Qt.WA_StyledBackground, True)
        self.setStyleSheet('DrawerWidget{background:white;}')
        self.lineedit = QLineEdit(self)


        layout = QVBoxLayout(self)
        layout.addWidget(self.lineedit)
        layout.addWidget(QPushButton('button', self,clicked=self._click))
        layout.addWidget(QPushButton('button2', self, clicked=self._click2))



    def _click(self):
        if self.lineedit.text() != "":
            print("框中輸入的文字為:{}".format(self.lineedit.text()))
            self.lineedit.clear()
        else:
            print("框中未輸入的文字為")

    def _click2(self):
        print("沒用")





class Window(QWidget):
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        self.resize(480, 960)
        self.entermouse = 0
        self.flag = 0

        self.x = 0
        self.y = 0
        # layout = QGridLayout(self)
        # layout.addWidget(QPushButton('側(cè)邊欄', self, clicked=self.doOpenLeft), 1, 0)

    def mouseMoveEvent(self, event):
        print("-----------------------mouseMoveEvent-----------------------")
        if self.entermouse == 1:
            self.x = event.x()
            self.y = event.y()
            self.flag = 1
            if self.x < 100 :
                self.doOpenLeft()
        self.update()


    def mousePressEvent(self, event):
        if self.entermouse == 1 and self.flag == 1 and event.button() == Qt.LeftButton:
            self.x = event.x()
            self.y = event.y()
            print("按壓 ",self.x,self.y)

        else:
            pass
        self.update()



    def mouseReleaseEvent(self, event):
        if self.entermouse == 1 and self.flag == 1 and event.button() == Qt.LeftButton:
            self.x = event.x()
            self.y = event.y()
            print("松開 ", self.x, self.y)
        else:
            pass
        self.update()

    def enterEvent(self, *args, **kwargs):
        if self.entermouse == 0:
            self.entermouse = 1
        else:
            pass

    def leaveEvent(self, *args, **kwargs):
        if self.entermouse == 1:
            self.entermouse = 0
        else:
            pass



    def doOpenLeft(self):
        if not hasattr(self, 'leftDrawer'):
            self.leftDrawer = CDrawer(self, direction=CDrawer.LEFT)
            self.leftDrawer.setWidget(DrawerWidget(self.leftDrawer))
        self.leftDrawer.show()

    def paintEvent(self, event):
        super().paintEvent(event)
        self.painter = QPainter()
        self.painter.begin(self)
        self.update()
        if self.x != 0 and self.y != 0 and self.entermouse == 1:
            # print("self.x,self.y ",self.x,self.y)
            self.update()
        else:
            self.update()
        self.update()
        self.painter.end()







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

到此這篇關(guān)于PyQt5實現(xiàn)平滑移動側(cè)邊菜單欄效果的示例的文章就介紹到這了,更多相關(guān)PyQt5 平滑移動側(cè)邊菜單欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • 利用python-pypcap抓取帶VLAN標簽的數(shù)據(jù)包方法

    利用python-pypcap抓取帶VLAN標簽的數(shù)據(jù)包方法

    今天小編就為大家分享一篇利用python-pypcap抓取帶VLAN標簽的數(shù)據(jù)包方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07
  • python在html中插入簡單的代碼并加上時間戳的方法

    python在html中插入簡單的代碼并加上時間戳的方法

    今天小編就為大家分享一篇python在html中插入簡單的代碼并加上時間戳的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • Python自動化辦公之Excel、Word和PDF操作指南

    Python自動化辦公之Excel、Word和PDF操作指南

    在現(xiàn)代辦公環(huán)境中,我們每天都要處理大量的文檔工作,Python作為一門功能強大的編程語言,提供了豐富的庫來簡化辦公文檔的處理任務(wù),下面就跟隨小編一起學習一下吧
    2025-10-10
  • pandas實現(xiàn)數(shù)據(jù)合并的示例代碼

    pandas實現(xiàn)數(shù)據(jù)合并的示例代碼

    本文主要介紹了pandas實現(xiàn)數(shù)據(jù)合并的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-05-05
  • 使用Python實現(xiàn)自動填入密碼功能

    使用Python實現(xiàn)自動填入密碼功能

    對于頻繁使用的軟件,每次都手動輸入密碼可能會顯得繁瑣,所以本文主要為大家詳細介紹了如何使用Python實現(xiàn)自動填入密碼功能,需要的可以參考下
    2024-04-04
  • Python最常用的20 個包總結(jié)

    Python最常用的20 個包總結(jié)

    這篇文章主要介紹了Python最常用的20 個包總結(jié),在平時使用Python的過程中,需要用到很多有用的包,今天就來盤點一下常用的包,需要的朋友可以參考下
    2023-04-04
  • 基于Python實現(xiàn)簡單的學生點名系統(tǒng)

    基于Python實現(xiàn)簡單的學生點名系統(tǒng)

    現(xiàn)在的學生大部分都很積極,會主動舉手回答問題。但是,也會遇到一些不好的情況,比如年級越高主動舉手的人越少,所以本文做了一個隨機的學生點名系統(tǒng)可以幫老師解決這些問題
    2022-09-09
  • python類方法和靜態(tài)方法詳解

    python類方法和靜態(tài)方法詳解

    這篇文章主要為大家介紹了python類方法和靜態(tài)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01
  • python 實現(xiàn)aes256加密

    python 實現(xiàn)aes256加密

    這篇文章主要介紹了python 如何實現(xiàn)aes256加密,幫助大家更好的理解和學習python,感興趣的朋友可以了解下
    2020-11-11
  • 使用Python實現(xiàn)獲取本機當前用戶登陸過的微信ID

    使用Python實現(xiàn)獲取本機當前用戶登陸過的微信ID

    這篇文章主要為大家詳細介紹了如何使用Python實現(xiàn)獲取本機當前用戶登陸過的微信對應(yīng)的wxid,文中的示例代碼講解詳細,感興趣的小伙伴可以了解下
    2025-07-07

最新評論

偏关县| 安阳县| 原阳县| 芮城县| 玉山县| 洛南县| 东方市| 迭部县| 沧州市| 徐汇区| 阳原县| 邢台市| 涞水县| 大港区| 铜山县| 灌阳县| 福泉市| 丹寨县| 华蓥市| 简阳市| 旺苍县| 宾阳县| 会昌县| 宜宾县| 青神县| 鹤壁市| 辽宁省| 平湖市| 商都县| 延边| 全州县| 东山县| 读书| 皋兰县| 汝南县| 沁源县| 新河县| 宁阳县| 霍城县| 南昌县| 永寿县|