pyqt5抽屉面板例子

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QLabel
from PyQt5.QtCore import QPropertyAnimation, QRect

class Popup(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setFixedSize(300, 200)
        self.setStyleSheet("background-color: lightgray; border: 1px solid black;")
        layout = QVBoxLayout()
        self.label = QLabel("This is a popup!")
        layout.addWidget(self.label)
        self.setLayout(layout)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Popup Example")
        self.setGeometry(100, 100, 800, 600)

        self.popup = Popup(self)
        self.popup.setGeometry(250, -200, 300, 200)  # Initially hidden above the window

        self.show_popup_button = QPushButton("Show Popup", self)
        self.show_popup_button.clicked.connect(self.show_popup)
        self.show_popup_button.setGeometry(50, 50, 200, 50)

        self.hide_popup_button = QPushButton("Hide Popup", self)
        self.hide_popup_button.clicked.connect(self.hide_popup)
        self.hide_popup_button.setGeometry(50, 120, 200, 50)

    def show_popup(self):
        self.animation = QPropertyAnimation(self.popup, b"geometry")
        self.animation.setDuration(500)  # Animation duration in milliseconds
        start_rect = QRect(250, -200, 300, 200)
        end_rect = QRect(250, 50, 300, 200)
        self.animation.setStartValue(start_rect)
        self.animation.setEndValue(end_rect)
        self.animation.start()

    def hide_popup(self):
        self.animation = QPropertyAnimation(self.popup, b"geometry")
        self.animation.setDuration(500)  # Animation duration in milliseconds
        start_rect = QRect(250, 50, 300, 200)
        end_rect = QRect(250, -200, 300, 200)
        self.animation.setStartValue(start_rect)
        self.animation.setEndValue(end_rect)
        self.animation.start()

app = QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec_())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值