I have a QPlainTextEdit box in an application that shows information to the user. The application code is huge, so I'll just include the relevant part of the code:
class ProgressBox(QPlainTextEdit):
"""Represents the progress information box."""
def __init__(self, win):
"""Message box constructor."""
super().__init__(win)
self.setReadOnly(True)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.setStyleSheet("""
border: 1px inset grey; background-color: white; padding: 10px;
""")
def contextMenuEvent(self, event):
menu = QMenu(self)
menu.setStyleSheet("""
QMenu {
border: 1px inset grey;
background-color: #fff;
color: #000;
padding: 0;
}
QMenu:selected {
background-color: #ddf;
color: #000;
}
""")
clear_action = menu.addAction("Clear")
# copy_all_action = menu.addAction("Copy Selected")
action = menu.exec_(self.mapToGlobal(event.pos()))
if action:
if action == clear_action:
self.clear_text()
def add_text(self, text):
self.setPlainText(self.toPlainText() + text)
self.verticalScrollBar().setValue(
self.verticalScrollBar().maximum()
)
self.repaint()
app.processEvents()
def charCount(self):
return len(self.toPlainText())
def clear_text(self):
self.setPlainText("")
self.repaint()
The "progress box" is initiated using (where win = QMainWindow() ):
win.info_box = ProgressBox(self)
And updated using:
win.info_box.add_text("Blah, blah.")
Now, the problem I have is minor, but still annoying. The scrollbar for the QPlaintextEdit widget does not display correctly (it has no "handle"). See the image:
I would like the scrollbar in the red box to look the same as the scrollbar on the QTableWidget above it. Does anyone know how I can do this please?