1
我在Designer的幫助下,在PyQt4中設計了一個帶有QLineEdit
的窗口。我使用pyuic4
將.ui
轉換爲.py
。我創建了另一個.py
文件,並導入了子文件Ui_Class
。如何連接QLineEdit focusOutEvent
我想在QLineEdit
失去焦點時執行一些任務。
就行按鈕點擊事件我連接QLineEdit
失去焦點事件
我在Designer的幫助下,在PyQt4中設計了一個帶有QLineEdit
的窗口。我使用pyuic4
將.ui
轉換爲.py
。我創建了另一個.py
文件,並導入了子文件Ui_Class
。如何連接QLineEdit focusOutEvent
我想在QLineEdit
失去焦點時執行一些任務。
就行按鈕點擊事件我連接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)