QTextEdit - text color won't change
-
Hello everyone,
Usually I am pretty good at debugging issues, but this issue with the QTextEdit text color not changing has me really confused. I feel like I must be missing something small.
Basically I have inherited a QTextEdit for a custom class in order to log my compile information. When inserting the the logs into the QTextEdit I change the text color to display the current time in a different color than what the log information will be. But, no matter what I do the text color does not change. I also ran the debugger and it also seems that the text doesn't even get added until later after the
insertPlainText
function is called. So, this had me thinking maybe it was having issues since I also have 2 custom QTextEdits that insert text with syntax highlighting, but I disabled that and the text color still won't change when inserting the log text.Here is the .h for my custom QTextEdit class:
#ifndef OUTPUTTEXTEDIT_H #define OUTPUTTEXTEDIT_H #include <QTextEdit> #include <QColor> #include <QTime> class OutputTextEdit : public QTextEdit { Q_OBJECT QColor m_timeColor; QColor m_textColor; public: OutputTextEdit(QWidget* parent = nullptr); ~OutputTextEdit(); void insertCompileLog(const QString& text); void setTimeColor(const QColor color) { m_timeColor = color; } void setTextColor(const QColor color) { m_textColor = color; } private: void setup(); }; #endif // OUTPUTTEXTEDIT_H
Here is the .cpp for my custom QTextEdit class:
#include "OutputTextEdit.h" OutputTextEdit::OutputTextEdit(QWidget* parent) : QTextEdit(parent), m_timeColor(QColor(16, 144, 144)), m_textColor(QColor(234, 221, 158)) { setup(); } OutputTextEdit::~OutputTextEdit() { } void OutputTextEdit::insertCompileLog(const QString &text) { // Ensures the cursor is at the end before inserting text QTextCursor myCursor = this->textCursor(); myCursor.movePosition(QTextCursor::End); this->setTextCursor(myCursor); // Add the time that the shader compiled this->setTextColor(m_timeColor); this->insertPlainText(QTime::currentTime().toString() + "\n"); // Insert the log text this->setTextColor(m_textColor); this->insertPlainText(text); } void OutputTextEdit::setup() { this->setReadOnly(true); this->setWordWrapMode(QTextOption::NoWrap); //this->setStyleSheet("color:red;"); }
Screenshot of my text:
Has anyone ever experienced an issue like this before?
Thank you for the help!
-
Well, couldn't figure out why text color wasn't changing, so I just decided to use my custom syntax highlighter to deal with changing the text color and it works quite well.