我第一次使用python3.4和qt5。这很简单,我可以理解我需要的大部分功能。但是(总是有“但是”)我不明白如何使用focusOut
/clearFocus
/focusIn
事件。在
我说得对吗
QObject.connect(self.someWidget, QtCore.SIGNAL('focusOutEvent()'), self.myProcedure)
…在第5季度不起作用?在
我试图理解this但没有成功。我将非常感谢一个简短的例子,如何在许多QLineEdit
失去注意力时捕捉事件。在
Tags:
这里的问题是
focusInEvent
/clearFocus
/focusOutEvent
是不是信号,它们是事件处理程序。请参见示例here。如果要捕捉这些事件,则需要在对象上重新实现事件处理程序,例如通过子类化QLineEdit。在在PyQt5中,信号本身的语法要简单得多。以来自QLineEdit的
^{pr2}$textEdited
信号为例,可以使用如下所示:这将把
self.myProcedure
函数连接到textEdited
信号。目标函数需要接受事件输出,例如:因此,您可以在类中定义
self.myProcedure
,它将接收由该事件发送的QString
:也可以按如下方式定义自定义事件:
在每种情况下,
pyqtSignal
都用于定义Foo
类的属性,您可以像任何其他信号一样连接到该类。例如,为了处理上述问题,我们可以创建:然后,}事件如下:
connect()
和{您发布的链接给出了more information on custom events、信号命名和新语法重载。在
相关问题 更多 >
编程相关推荐