gpt4 book ai didi

python - 如何连接 QLineEdit focusOutEvent

转载 作者:行者123 更新时间:2023-11-28 20:08:04 24 4
gpt4 key购买 nike

在 Designer 的帮助下,我在 PyQt4 中设计了一个带有 QLineEdit 的窗口。我使用 pyuic4.ui 转换为 .py。我创建了另一个 .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)

关于python - 如何连接 QLineEdit focusOutEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15066913/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com