如何连接 QLineEdit focusOutEvent [英] How to connect QLineEdit focusOutEvent
本文介绍了如何连接 QLineEdit focusOutEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在设计器的帮助下在 PyQt4 中设计了一个带有 QLineEdit
的窗口.我使用 pyuic4
将 .ui
转换为 .py
.我创建了另一个 .py
文件并导入和子类化 Ui_Class
.
I have designed a window with a QLineEdit
in PyQt4 with the help of Designer. I converted .ui
to .py
using pyuic4
. I created another .py
file and imported and subclassed Ui_Class
.
我想在 QLineEdit
失去焦点时执行一些任务.
I want to perform some task when QLineEdit
lost focus.
仅行按钮单击事件 i 连接 QLineEdit
失去焦点事件
Just line button clicked event i to connect QLineEdit
Lost focus event
推荐答案
使用 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)
这篇关于如何连接 QLineEdit focusOutEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文