【发布时间】:2013-02-25 12:23:25
【问题描述】:
在 Designer 的帮助下,我在 PyQt4 中设计了一个带有 QLineEdit 的窗口。我使用pyuic4 将.ui 转换为.py。我创建了另一个.py 文件并导入并继承了Ui_Class。
我想在QLineEdit失去焦点时执行一些任务。
刚线按钮点击事件i连接QLineEdit失去焦点事件
【问题讨论】:
在 Designer 的帮助下,我在 PyQt4 中设计了一个带有 QLineEdit 的窗口。我使用pyuic4 将.ui 转换为.py。我创建了另一个.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)
【讨论】: