I am experiencing a rather strange issue with my PyQT QTextEdit.
When I enter a string from my QLineEdit it adds it but say I enter another the first string disappea
The setText()
method replaces all the current text, so you just need to use the append()
method instead. (Note that both these methods automatically add a trailing newline).
import sys
from PyQt4 import QtGui
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
layout = QtGui.QVBoxLayout(self)
self.button = QtGui.QPushButton('Test')
self.edit = QtGui.QTextEdit()
layout.addWidget(self.edit)
layout.addWidget(self.button)
self.button.clicked.connect(self.handleTest)
def handleTest(self):
self.edit.append('spam: spam spam spam spam')
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec_())