QLineEdit
Designerを使用して、PyQt4でウィンドウを設計しました。を使用して変換.ui
しました。別のファイルを作成し、インポートしてサブクラス化しました。.py
pyuic4
.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)