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
After clicking the "set text" button
After clicking the "append text" button
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())