[英]How to connect QLineEdit focusOutEvent
我在Designer的幫助下在PyQt4中設計了一個帶有QLineEdit
的窗口。 我使用pyuic4
將.ui
轉換為.py
。 我創建了另一個.py
文件並導入和子類化了Ui_Class
。
我想在QLineEdit
失去焦點時執行一些任務。
只需按行按鈕點擊事件i即可連接QLineEdit
Lost焦點事件
使用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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.