python - 从线程调用的类中的动画函数不起作用
问题描述
我有一个 qt5 ui 文件,我正在通过一个具有淡入/淡出功能的类加载它:
class LoadingScreen(QWidget):
def __init__(self):
super(LoadingScreen, self).__init__()
loader = QUiLoader()
file = QFile("loading_screen.ui")
file.open(QFile.ReadOnly)
global loading_screen
loading_screen = loader.load(file, self)
file.close()
self.initUI()
def fadeIN(self):
self.fade_in = QPropertyAnimation(self,"windowOpacity")
self.fade_in.setDuration(500)
self.fade_in.setStartValue(0.0)
self.fade_in.setEndValue(1.0)
self.fade_in.setEasingCurve(QEasingCurve.InBack)
self.fade_in.start()
self.show()
def fadeOUT(self):
self.fade_out = QPropertyAnimation(self,"windowOpacity")
self.fade_out.setDuration(500)
self.fade_out.setStartValue(1.0)
self.fade_out.setEndValue(0.0)
self.fade_out.setEasingCurve(QEasingCurve.OutBack)
self.fade_out.start()
我正在加载它:
global loading_screen_window
loading_screen_window = LoadingScreen()
然后我启动一个线程,它正在做一些事情,比如阅读配置:
config_thread = config(1,"config",1)
config_thread.start()
工作正常,在线程的某个点我想调用我的 LoadingScreen() 类的淡出函数。函数被执行但动画不起作用?我究竟做错了什么?在其他地方调用淡出函数表单有效,但不在我的线程内。
我正在使用 Python 2.7、Qt5 和 PySide2。
谢谢你的帮助!!
解决方案
我找到了一个解决方案:
class LoadingScreen(QWidget):
def __init__(self):
super(LoadingScreen, self).__init__()
loader = QUiLoader()
file = QFile("loading_screen.ui")
file.open(QFile.ReadOnly)
global loading_screen
loading_screen = loader.load(file, self)
file.close()
self.initUI()
#Config Thread starten
self.config_thread = config()
self.config_thread.finished.connect(self.fadeOUT)
self.config_thread.start()
感谢您的帮助 eyllanesc :)
推荐阅读
- python - Matplotlib 标记注释字体大小在 PDF 中不会缩小到 1pt 以下
- sql - 在 PL/pgSQL 函数中拆分逗号分隔的字符串
- azure - 错误 - 警告:模块“Az.Accounts”的版本“1.9.4”当前正在使用中。Powershell 脚本在 Azure 云中的 VM 上运行
- emeditor - 如何在 emeditor 中自动选择和复制过滤后的结果
- elasticsearch - 包含数组中所有值的弹性匹配文档
- html - 添加谷歌地图,用户可以在我的应用程序上输入路线
- python - 使用 Python 进行 Elasticsearch 多查询/搜索
- html - 如何在我的 GitHub.io 托管网站上启用下载?
- java - 我如何更新数据库中的通话记录数据最新(java android)
- python - Python:如何根据字符串输入获得多个字符串输出?