[英]How to connect QLineEdit focusOutEvent
我在Designer的帮助下在PyQt4中设计了一个带有QLineEdit
的窗口。 我使用pyuic4
将.ui
转换为.py
。 我创建了另一个.py
文件并导入和子类化了Ui_Class
。
我想在QLineEdit
失去焦点时执行一些任务。
只需按行按钮点击事件i即可连接QLineEdit
Lost焦点事件
使用eventFilter
:
class Filter(QtCore.QObject):
def eventFilter(self, widget, event):
# FocusOut event
if event.type() == QtCore.QEvent.FocusOut:
# do custom stuff
print 'focus out'
# return False so that the widget will also handle the event
# otherwise it won't focus out
return False
else:
# we don't care about other events
return False
在你的窗口:
# ...
self._filter = Filter()
# adjust for your QLineEdit
self.ui.lineEdit.installEventFilter(self._filter)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.