pyqt5 捕捉全局异常并弹窗显示

pyqt利用sys.excepthook来对全局异常进行捕获,并输出显示

import os
import traceback

class Mainworkwindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
您可以使用QDialog和QPropertyAnimation来创建一个自定义的可滑动弹窗。 首先,您需要创建一个新的QWidget或QDialog作为您的弹窗。然后,您需要将其设置为不可见,并将其放置在屏幕外部。 接下来,您需要使用QPropertyAnimation来创建动画效果。您可以使用QVariantAnimation来实现滑动效果,例如将窗口从屏幕外部滑动到心。 下面是一个示例代码,演示如何创建一个自定义的可滑动弹窗: ```python from PyQt5.QtCore import QRect, QPropertyAnimation, QVariantAnimation from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QPushButton class CustomDialog(QDialog): def __init__(self, parent=None): super(CustomDialog, self).__init__(parent) # 设置窗口大小和位置 self.setGeometry(QRect(1000, 100, 200, 200)) # 设置布局 self.layout = QVBoxLayout(self) # 添加标签和按钮 self.label = QLabel("This is a custom dialog") self.layout.addWidget(self.label) self.button = QPushButton("Close") self.button.clicked.connect(self.close) self.layout.addWidget(self.button) # 创建动画效果 self.animation = QPropertyAnimation(self, b"pos") self.animation.setDuration(1000) def showEvent(self, event): # 在弹窗显示时,启动动画效果 self.animation.setStartValue(self.pos()) self.animation.setEndValue(QRect(400, 400, 200, 200).center()) self.animation.start() super(CustomDialog, self).showEvent(event) def closeEvent(self, event): # 在弹窗关闭时,启动动画效果 self.animation.setStartValue(self.pos()) self.animation.setEndValue(QRect(1000, 100, 200, 200).topLeft()) self.animation.finished.connect(super(CustomDialog, self).closeEvent) self.animation.start() ``` 在这个示例,我们创建了一个名为CustomDialog的子类,它继承自QDialog。在构造函数,我们设置了窗口的大小和位置,并创建了布局和控件。 在showEvent()函数,我们启动了QPropertyAnimation动画效果。我们将当前窗口的位置设置为初始值,并将结束值设置为屏幕央。在closeEvent()函数,我们启动了另一个动画效果,将当前窗口位置设置为初始值,并将结束值设置为屏幕外部。这样可以实现弹窗的滑动效果。 最后,在您的主窗口,您可以使用以下代码来创建并显示CustomDialog: ```python dialog = CustomDialog(self) dialog.exec_() ``` 这将创建一个CustomDialog实例,并将其显示为模态对话框。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值