I want to do some action if the user typed text into the QLineEdit and left the QLineEdit entry field.
There is not a lot of explanation about focusInEvent
available. I'm using Python and PySide2. But all information is helping.
def check_focus(self, event):
print('Focus in event')
# Way one I tried
if QtGui.QFocusEvent.lostFocus(self.LE_sample_input_01):
if self.LE_sample_input_01.text():
print("Lost focus")
# Way two I tried
if event.type() == QtCore.QEvent.FocusIn:
if self.LE_sample_input_01.text():
print(f"Lost focus")
# Way three I tried
if self.LE_sample_input_01.focusInEvent(event)
Simple example with two QLineEdits
So it's possible to leave one entry
from PySide2 import QtWidgets, QtCore, QtGui
from PySide2.QtGui import QIcon
class QTApp(QtWidgets.QWidget):
def __init__(self):
super(QTApp, self).__init__()
self.LE_sample_input_01 = QtWidgets.QLineEdit()
self.LE_sample_input_02 = QtWidgets.QLineEdit()
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.LE_sample_input_01)
layout.addWidget(self.LE_sample_input_02)
self.setLayout(layout)
def check_focus(self, event):
print('focus out event')
# if QtGui.QFocusEvent.lostFocus(self.LE_client_name):
# print("lost focus") self.LE_client_name.focusInEvent(event)
if event.type() == QtCore.QEvent.FocusIn:
if self.LE_sample_input_01.text():
print(f"Lost focus")
if __name__ == '__main__':
app = QtWidgets.QApplication()
qt_app = QTApp()
qt_app.show()
app.exec_()