From f77ab0e1997b5fae48e3c7672b00a812c72dee87 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Sun, 27 Feb 2022 18:56:19 +1100 Subject: [PATCH] UI: Fix rendering of spaces & tabs in Log Viewer For some reason, the combination of QPlainTextEdit and a HTML block seems to treat spaces as HTML shoult (only display one, no tabs, etc) rather than how QTextEdit + HTML does, which is strange. As we don't need HTML for existing log lines, insert them as plaintext, but for new entries wrap non-error non-warning messages in a tag and format that with white-space: pre --- UI/log-viewer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/UI/log-viewer.cpp b/UI/log-viewer.cpp index 021450069..18702e3f4 100644 --- a/UI/log-viewer.cpp +++ b/UI/log-viewer.cpp @@ -27,6 +27,9 @@ OBSLogViewer::OBSLogViewer(QWidget *parent) : QDialog(parent) textArea = new QPlainTextEdit(); textArea->setReadOnly(true); textArea->setFont(fixedFont); + // Fix display of tabs & multiple spaces + textArea->document()->setDefaultStyleSheet( + "font { white-space: pre; }"); QHBoxLayout *buttonLayout = new QHBoxLayout(); QPushButton *clearButton = new QPushButton(QTStr("Clear")); @@ -112,7 +115,7 @@ void OBSLogViewer::InitLog() cursor.beginEditBlock(); while (!in.atEnd()) { QString line = in.readLine(); - cursor.insertHtml(line); + cursor.insertText(line); cursor.insertBlock(); } cursor.endEditBlock(); @@ -136,6 +139,9 @@ void OBSLogViewer::AddLine(int type, const QString &str) case LOG_ERROR: msg = QString("%1").arg(msg); break; + default: + msg = QString("%1").arg(msg); + break; } QScrollBar *scroll = textArea->verticalScrollBar();