How to connect QLineEdit focusOutEvent

孤街醉人 提交于 2020-01-04 09:16:38

问题


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.

I want to perform some task when QLineEdit lost focus.

Just line button clicked event i to connect QLineEdit Lost focus event


回答1:


Use an 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

And in your window:

# ...
self._filter = Filter()
# adjust for your QLineEdit
self.ui.lineEdit.installEventFilter(self._filter)


来源:https://stackoverflow.com/questions/15066913/how-to-connect-qlineedit-focusoutevent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!