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
def __init__(self):
super().__init__()
self.ex_frame.setObjectName("ex_frame")
self.ex_out.setReadOnly(True)
self.ex_out.setObjectName("ex_out")
self.ex_in.setFocus(True)
self.ex_in.setObjectName("ex_in")
self.ex_in.returnPressed.connect(self.execute_command)
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__':
Ex = Example()
sys.exit(app.exec_())
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_command)
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_())
To copy to clipboard, switch view to plain text mode
Any help would be appreciated. Thanks.
Bookmarks