在Designer的帮助下,我用PyQt4设计了一个带有QLineEdit的窗口。我使用pyuic4将.ui转换为.py。我创建了另一个.py文件并导入了Ui_Class并子类化了它。
当QLineEdit失去焦点时,我想执行一些任务。
只需线路按钮点击事件I即可连接QLineEdit失去焦点事件
发布于 2013-02-25 23:07:39
使用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)https://stackoverflow.com/questions/15066913
复制相似问题