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 <font> tag and
format that with white-space: pre
This commit is contained in:
Matt Gajownik 2022-02-27 18:56:19 +11:00
parent fe71841b5a
commit f77ab0e199

View File

@ -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("<font color=\"#c00000\">%1</font>").arg(msg);
break;
default:
msg = QString("<font>%1</font>").arg(msg);
break;
}
QScrollBar *scroll = textArea->verticalScrollBar();