我尝试在PyQt中发出自定义事件。一个小部件将发出,另一个小部件将侦听事件,但这两个小部件不需要关联。在
在JavaScript中,我可以通过
// Component 1
document.addEventListener('Hello', () => console.log('Got it'))
// Component 2
document.dispatchEvent(new Event("Hello"))
编辑:我知道信号和插槽,但只知道如何在父子之间使用它们。如何在任意不相关的小部件之间使用这种机制(或其他机制)?在
在PyQt中,以下指令:
相当于
^{pr2}$以类似的方式:
相当于
但最大的区别在于“document”对象的范围,因为连接是在全局元素之间的。但在PyQt中,这个元素不存在。在
模拟您指出的行为的一种方法是创建全局对象:
globalobject.py
主.py
相关问题 更多 >
编程相关推荐