PDA

View Full Version : PyQt5 QTextEdit limiting buffer



blissend
4th November 2015, 21:01
Is it possible to use PyQt5 to limit the number of lines in QTextEdit? I read about setMaximumBlockCount but can't seem to figure out how to actually use it on QTextEdit. Would anyone have an example they could give me? Here's a sample code I would like to use to do something like that...


import sys
from PyQt5.QtWidgets import (QMainWindow, QTextEdit, QApplication, QLineEdit,
QVBoxLayout, QFrame)

class Example(QMainWindow):
def __init__(self):
super().__init__()
self.ex_frame = QFrame(self)
self.ex_frame.setObjectName("ex_frame")

self.ex_out = QTextEdit(self.ex_frame)
self.ex_out.setReadOnly(True)
self.ex_out.setObjectName("ex_out")
self.ex_in = QLineEdit(self.ex_frame)
self.ex_in.setFocus(True)
self.ex_in.setObjectName("ex_in")
self.ex_in.returnPressed.connect(self.execute_comm and)
vbox = QVBoxLayout(self.ex_frame)
vbox.addWidget(self.ex_out)
vbox.addWidget(self.ex_in)
self.setCentralWidget(self.ex_frame)

self.setGeometry(300, 300, 720, 480)
self.setWindowTitle('Example')
self.show()

def execute_command(self):
self.ex_out.append(self.ex_in.text())
self.ex_in.setText('')

if __name__ == '__main__':
app = QApplication(sys.argv)
Ex = Example()
sys.exit(app.exec_())

Any help would be appreciated. Thanks.

blissend
6th November 2015, 22:08
The workaround I have in the meantime is to get the html into a string (since I do use the limited html) and do operations on the string. The problem with that is that I can't cut from anywhere when html is involved.