简体   繁体   English

如何连接QLineEdit focusOutEvent

[英]How to connect QLineEdit focusOutEvent

I have designed a window with a QLineEdit in PyQt4 with the help of Designer. 我在Designer的帮助下在PyQt4中设计了一个带有QLineEdit的窗口。 I converted .ui to .py using pyuic4 . 我使用pyuic4.ui转换为.py I created another .py file and imported and subclassed Ui_Class . 我创建了另一个.py文件并导入和子类化了Ui_Class

I want to perform some task when QLineEdit lost focus. 我想在QLineEdit失去焦点时执行一些任务。

Just line button clicked event i to connect QLineEdit Lost focus event 只需按行按钮点击事件i即可连接QLineEdit Lost焦点事件

Use an eventFilter : 使用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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM