[Python] How to manage QLineEdit.returnPressed signal from multiple QLineEdit? [duplicate]

Discussão em 'Python' iniciado por Stack, Março 19, 2025.

  1. Stack

    Stack Membro Participativo

    Using qtpy (and the actual Qt5 behind):

    from qtpy.QtWidgets import QApplication, QMainWindow, QLineEdit

    class MainWindow(QMainWindow):
    def __init__(self):
    super().__init__()
    widget = QLineEdit()
    widget.setPlaceholderText("Enter your text")
    widget.returnPressed.connect(self.le_return_pressed)
    self.setCentralWidget(widget)
    self.le = widget

    def le_return_pressed(self):
    print(f'Line edit text: {self.le.text()}')

    def main():
    app = QApplication([])
    window = MainWindow()
    window.show()
    app.exec()

    if __name__ == '__main__':
    main()


    In the signal handler le_return_pressed I need to use a hard reference self.le to the widget to access its properties. If the handler is common to multiple QLineEdit, how to identify the signal source?

    Continue reading...

Compartilhe esta Página