首页 > 编程语言 > 详细

PyQt5弹框定时关闭(python)

时间:2020-11-19 18:33:19      阅读:423      评论:0      收藏:0      [点我收藏+]

PyQt5使用QMessageBox,可以设置在几秒后关闭  (作者使用的python3)

info_box = QMessageBox()
# 因为没使用这种方式 QMessageBox.information(self, ‘复制‘, ‘复制成功‘, QMessageBox.Yes) 写弹出框,
# 则主窗口的样式不能应用在QMessageBox中,因此重新写了弹出框的部件样式

info_box.setStyleSheet(‘QPushButton{font-weight: bold; background: skyblue; border-radius: 14px;‘
‘width: 64px; height: 28px; font-size: 20px; text-align: center;}‘
‘QLabel{font-weight: bold; font-size: 20px; color: orange}‘
)
info_box.setIconPixmap(QPixmap(pic_path))        # 自定义QMessageBox中间的图片
info_box.setWindowIcon(QIcon(‘pics/icon1.gif‘))    # 自定义QMessageBox左上角的小图标
info_box.setWindowTitle(title)     # QMessageBox标题
info_box.setText(text)     #  QMessageBox的提示文字
info_box.setStandardButtons(QMessageBox.Ok)      # QMessageBox显示的按钮
info_box.button(QMessageBox.Ok).animateClick(t)    # t时间后自动关闭(t单位为毫秒)
info_box.exec_()    # 如果使用.show(),会导致QMessageBox框一闪而逝

样式如下,1s弹框会自动关闭,:

技术分享图片     技术分享图片

如果使用QMessageBox.information(self, ‘复制‘, ‘复制成功‘, QMessageBox.Yes) ,弹框的部件会使用主窗口的通用样式,但是不支持上面的这种定时关闭办法;

后来寻思着使用Qtimer定时器定时关闭弹框的,但是没能成功。如果哪位老哥实现了定时器关闭弹框,请教教我,感激不尽。

PyQt5弹框定时关闭(python)

原文:https://www.cnblogs.com/lipx9527/p/14007001.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!