首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何连接QLineEdit focusOutEvent

如何连接QLineEdit focusOutEvent
EN

Stack Overflow用户
提问于 2013-02-25 20:23:25
回答 1查看 5.4K关注 0票数 2

在Designer的帮助下,我用PyQt4设计了一个带有QLineEdit的窗口。我使用pyuic4.ui转换为.py。我创建了另一个.py文件并导入了Ui_Class并子类化了它。

QLineEdit失去焦点时,我想执行一些任务。

只需线路按钮点击事件I即可连接QLineEdit失去焦点事件

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-25 23:07:39

使用eventFilter

代码语言:javascript
复制
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

在你的窗口中:

代码语言:javascript
复制
# ...
self._filter = Filter()
# adjust for your QLineEdit
self.ui.lineEdit.installEventFilter(self._filter)
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15066913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档