I'm trying to understand why QLineEdit "editingFinished" signals are generated when other widgets are selected. In the example below the "on_lineedit" method is called when the combo box is selected. Why?
import sys
from PyQt5 import QtWidgets
class MyApp(QtWidgets.QDialog):
def __init__(self, *args):
super().__init__(*args)
# create combobox:
combobox = QtWidgets.QComboBox(self)
combobox.addItems(['Item 1', 'Item 2'])
# create line edit
lineedit = QtWidgets.QLineEdit(self)
lineedit.editingFinished.connect(self.on_lineedit)
# layout:
vbox = QtWidgets.QVBoxLayout()
vbox.addWidget( combobox )
vbox.addWidget( lineedit )
self.setLayout(vbox)
def on_lineedit(self):
print('on_lineedit')
app = QtWidgets.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
I know that this issue can be avoided by connecting the "textChanged" signal instead of the "editingFinished" signal like this:
lineedit.textChanged.connect(self.on_lineedit)
and I've seen similar issues raised elsewhere (links below) but I still don't understand why the "editingFinished" signal is generated when the combobox is selected.
Qt qspinbox editingFinished signal on value changed
Suppress QLineEdit editingFinished signal when certain button is clicked