Index: components/viewer/viewercontrol.pas
===================================================================
--- components/viewer/viewercontrol.pas	(revision 8456)
+++ components/viewer/viewercontrol.pas	(working copy)
@@ -1905,7 +1905,9 @@
   StartPos: PtrInt; DataLength: Integer);
 var
   sBefore: String;
+{$IF DEFINED(DARWIN) and DEFINED(LCLQT)}
   iBefore: Integer = 0;
+{$ENDIF}
   pBegLine, pEndLine: PtrInt;
   iBegDrawIndex, iEndDrawIndex: PtrInt;
 begin
@@ -1937,7 +1939,9 @@
   if iBegDrawIndex - pBegLine > 0 then
   begin
     sBefore := GetText(StartPos, iBegDrawIndex - pBegLine, 0);
+{$IF DEFINED(DARWIN) and DEFINED(LCLQT)}
     iBefore := Canvas.TextWidth(sBefore);
+{$ENDIF}
   end;
 
   // Text before selection + selected text
@@ -1946,11 +1950,10 @@
   Canvas.Brush.Color := clHighlight;
   Canvas.Font.Color  := clHighlightText;
 
-  // Cannot simply draw text with brush with TextOut
-  // because it differs between widgetsets.
-  Canvas.Brush.Style := bsSolid;
+{$IF DEFINED(DARWIN) and DEFINED(LCLQT)}
+  // Workaround for the unpainted background bug on macOS with Qt widgetset
   Canvas.FillRect(Bounds(X + iBefore, Y, Canvas.TextWidth(sText) - iBefore, FTextHeight));
-  Canvas.Brush.Style := bsClear;
+{$ENDIF}
   Canvas.TextOut(X, Y, sText);
 
   // Restore previous canvas settings
@@ -1958,11 +1961,11 @@
   Canvas.Font.Color  := Font.Color;
 
   // Text before selection
-  if iBefore > 0 then
+  if iBegDrawIndex - pBegLine > 0 then
   begin
-    Canvas.Brush.Style := bsSolid;
+{$IF DEFINED(DARWIN) and DEFINED(LCLQT)}
     Canvas.FillRect(Bounds(X, Y, iBefore, FTextHeight));
-    Canvas.Brush.Style := bsClear;
+{$ENDIF}
     Canvas.TextOut(X, Y, sBefore);
   end;
 end;
