【问题标题】:How to connect QLineEdit focusOutEvent如何连接 QLineEdit focusOutEvent
【发布时间】:2013-02-25 12:23:25
【问题描述】:

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

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

刚线按钮点击事件i连接QLineEdit失去焦点事件

【问题讨论】:

    标签: python pyqt4 qlineedit


    【解决方案1】:

    使用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)
    

    【讨论】:

      猜你喜欢
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 2014-01-02
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      相关资源
      最近更新 更多