0

I use pyqt5 to practice using the QplainTextEdit control. Click QpushButton to display the set text or append text in QplainTextEdit, but it will not be displayed immediately. You need to click and drag to display it. What is the problem?

Attached (use environment):

MacOS 10.13.6
python3.7.6
pycharm
pyqt5.13.2

enter image description here After clicking the "set text" button enter image description here After clicking the "append text" button enter image description here After clicking and dragging with the mouse This is all my code:

from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPlainTextEdit, QPushButton
import sys


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.InitWindow()

    def InitWindow(self):
        self.setWindowTitle("PyQt5 PlainTextEdit")
        self.setGeometry(400, 300, 400, 300)
        self.plainText = QPlainTextEdit()
        self.plainText.setPlaceholderText("This is some text for our plaintextedit")
        self.btn = QPushButton('set text')
        self.btn.clicked.connect(self.setText)
        self.btn2 = QPushButton('append text')
        self.btn2.clicked.connect(self.appendText)
        vbox = QVBoxLayout()
        vbox.addWidget(self.plainText)
        vbox.addWidget(self.btn)
        vbox.addWidget(self.btn2)
        self.setLayout(vbox)

    def setText(self):
        print("set text button click")
        self.plainText.setPlainText('This is set text')

    def appendText(self):
        print("append text button click")
        self.plainText.appendPlainText('This is append text')


if __name__ == '__main__':
    App = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(App.exec())
sudo97
  • 904
  • 2
  • 11
  • 22
pymark
  • 31
  • 1
  • try add `self.plainText.repaint()` – eyllanesc Feb 20 '20 at 01:21
  • 1
    I ran your code and did not experience the issue (using v 5.9.2) . I wouldn't be surprised if pyqt 5.13 is just a less stable version because it was only recently released. You can install a specific version for instance with `pip install PyQt5==5.9.2` – alec Feb 20 '20 at 03:48
  • Thank you very much. It works. @eyllanesc – pymark Feb 21 '20 at 04:42
  • pip install PyQt5==5.9.2, When I do it. It work! Thank you very much! @alec – pymark Feb 21 '20 at 04:44

0 Answers0