我在Designer的帮助下在PyQt4中设计了一个带QLineEdit
的窗口。我使用.ui
将.py
转换为pyuic4
。我创建了另一个.py
文件并导入和子类化了Ui_Class
。
我希望在QLineEdit
失去焦点时执行一些任务。
点击线按钮点击事件i以连接QLineEdit
丢失焦点事件
答案 0 :(得分:7)
使用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)