[Ipe-discuss] LaTeX code unreadable in Edit Text Object window on a dark theme

Otfried Cheong ipe at otfried.org
Thu May 27 09:59:08 CEST 2021


On Wed, May 26, 2021, at 22:37, Soeren Nickel via Ipe-discuss wrote:
> I am also working on Mint, using a dark Theme and was bothered by that 
> in the past. I tried to use qt5ct to define a stylesheet, which takes 
> care of that, but only plain text (i.e. the text, which was previously 
> uncolored) reacted to it. A colleague of mine looked into it. He found 
> that the file /ipeui/ipeui_qt.cpp contains
> 
> void LatexHighlighter::highlightBlock (see attached image)
> 
> which defines the hardcoded mathFormat and tagFormat, which was already 
> mentioned. Plain text is not adressed here, which is probably, why it 
> reacted to the qt stylesheet. I would assume, if you change the defined 
> colors in this file and recompile, then this issue should be resolved.

Exactly.   Here is a patch that will fix it with different hardcoded colors:

---------------------------------------------------------------------------------
--- a/src/ipeui/ipeui_qt.cpp
+++ b/src/ipeui/ipeui_qt.cpp
@@ -69,10 +69,11 @@ void XmlHighlighter::applyFormat(const QString &text, QRegExp &exp,
 
 void XmlHighlighter::highlightBlock(const QString &text)
 {
+  bool dark = QGuiApplication::palette().text().color().value() > 128;
   QTextCharFormat tagFormat, stringFormat, numberFormat;
   tagFormat.setFontWeight(QFont::Bold);
-  tagFormat.setForeground(Qt::blue);
-  stringFormat.setForeground(Qt::darkMagenta);
+  tagFormat.setForeground(dark ? Qt::yellow : Qt::blue);
+  stringFormat.setForeground(dark ? Qt::cyan : Qt::darkMagenta);
   numberFormat.setForeground(Qt::red);
 
   QRegExp tagExp( "<.*>" );
@@ -114,10 +115,11 @@ void LatexHighlighter::applyFormat(const QString &text, QRegExp &exp,
 
 void LatexHighlighter::highlightBlock(const QString &text)
 {
+  bool dark = QGuiApplication::palette().text().color().value() > 128;
   QTextCharFormat mathFormat, tagFormat;
-  mathFormat.setForeground(Qt::red);
+  mathFormat.setForeground(dark ? Qt::cyan : Qt::red);
   tagFormat.setFontWeight(QFont::Bold);
-  tagFormat.setForeground(Qt::blue);
+  tagFormat.setForeground(dark ? Qt::yellow : Qt::blue);
 
   QRegExp mathExp( "\\$[^$]+\\$" );
   QRegExp tagExp( "\\\\[a-zA-Z]+" );
---------------------------------------------------------------------------------------------

It would be nicer to allow users to modify the colors with a Qt style sheet, feel free to submit a suitable patch.

Cheers,
  Otfried


More information about the Ipe-discuss mailing list