0

I have a textbox in my pyqt5 app, built with QTextEdit Class, and I need a function that immediately activates upon editing something in the textbox.

Is such thing possible?

  • Related: https://stackoverflow.com/questions/22531578/make-an-action-when-the-qlineedit-text-is-changed-programmatically – Thaer A Jun 13 '20 at 06:29

1 Answers1

1

According to qt documentation you can use QTextedit.textChanged() signal for this purpose.

Try this, will copy everything you writes on upper QTextedit at real time..

from PySide2.QtWidgets import QWidget, QApplication, QTextEdit, QVBoxLayout
import sys


class MainWindow(QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.layout = QVBoxLayout()
        self.text = QTextEdit()
        self.aux = QTextEdit()
        self.layout.addWidget(self.text)
        self.layout.addWidget(self.aux)

        self.setLayout(self.layout)
        self.text.textChanged.connect(self.onChange)

    def onChange(self):
        self.aux.setText(self.text.toPlainText())



if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())
jupiterbjy
  • 2,882
  • 1
  • 10
  • 28