QLineEdit
在 Designer 的帮助下,我在 PyQt4 中设计了一个带有 a 的窗口。我转换.ui
为.py
使用pyuic4
. 我创建了另一个.py
文件并导入和子类化Ui_Class
.
我想在QLineEdit
失去焦点时执行一些任务。
只需行按钮单击事件 i 即可连接QLineEdit
丢失焦点事件
使用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)