View Issue Details

IDProjectCategoryView StatusLast Update
0034587LazarusWidgetsetpublic2018-12-08 17:00
ReporterAlexander KoblovAssigned ToZeljan Rikalo 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86_64OSmacOSOS Version
Product Version2.1 (SVN)Product Build 
Target VersionFixed in Version 
Summary0034587: Canvas.TextOut does not draw background
DescriptionCanvas.TextOut does not draw background under macOS with Qt4 widgetset. Works fine with other widgetsets.
TagsNo tags attached.
Fixed in Revision59652,59667
LazTarget-
WidgetsetQT, QT5
Attached Files
  • TextOutBug.zip (130,727 bytes)
  • fix_qt4_darwin.patch (1,994 bytes)
    Index: qtobjects.pas
    ===================================================================
    --- qtobjects.pas	(revision 59665)
    +++ qtobjects.pas	(working copy)
    @@ -2822,6 +2822,10 @@
       To get a correct behavior we need to sum the text's height to the Y coordinate.
      ------------------------------------------------------------------------------}
     procedure TQtDeviceContext.drawText(x: Integer; y: Integer; s: PWideString);
    +{$IFDEF DARWIN}
    +var
    +  OldBkMode: Integer;
    +{$ENDIF}
     begin
       {$ifdef VerboseQt}
       Write('TQtDeviceContext.drawText TargetX: ', X, ' TargetY: ', Y);
    @@ -2842,11 +2846,20 @@
     
       // The ascent is only applied here, because it also needs
       // to be rotated
    +  {$IFDEF DARWIN}
    +  if getBKMode = OPAQUE then
    +    QPainter_fillRect(Widget, x, y - Metrics.ascent, Font.Metrics.width(s), Font.Metrics.height, QPainter_brush(Widget));
    +
    +  OldBkMode := SetBkMode(TRANSPARENT);
    +  {$ENDIF}
       if Font.Angle <> 0 then
         QPainter_drawText(Widget, 0, Metrics.ascent, s)
       else
         QPainter_drawText(Widget, x, y, s);
    -
    +  {$IFDEF DARWIN}
    +  SetBkMode(OldBkMode);
    +  {$ENDIF}
    +  
       RestorePenColor;
       
       // Restore previous angle
    @@ -2869,6 +2882,10 @@
       Returns: Nothing
      ------------------------------------------------------------------------------}
     procedure TQtDeviceContext.drawText(x, y, w, h, flags: Integer; s: PWideString);
    +{$IFDEF DARWIN}
    +var
    +  OldBkMode: Integer;
    +{$ENDIF}
     begin
       {$ifdef VerboseQt}
       Write('TQtDeviceContext.drawText x: ', X, ' Y: ', Y,' w: ',w,' h: ',h);
    @@ -2883,10 +2900,19 @@
       end;
     
       RestoreTextColor;
    +  {$IFDEF DARWIN}
    +  if getBKMode = OPAQUE then
    +    QPainter_fillRect(Widget, x, y, w, h, QPainter_brush(Widget));
    +
    +  OldBkMode := SetBkMode(TRANSPARENT);
    +  {$ENDIF}
       if Font.Angle <> 0 then
         QPainter_DrawText(Widget, 0, 0, w, h, Flags, s)
       else
         QPainter_DrawText(Widget, x, y, w, h, Flags, s);
    +  {$IFDEF DARWIN}
    +  SetBkMode(OldBkMode);
    +  {$ENDIF}
       RestorePenColor;
     
       // Restore previous angle
    
    fix_qt4_darwin.patch (1,994 bytes)

Activities

Alexander Koblov

2018-11-22 17:33

reporter  

TextOutBug.zip (130,727 bytes)

jamie philbrook

2018-11-22 18:06

reporter   ~0112113

I don't have a Mac but, Can you test or set the Brush.Style := bsSolid after
you set the color but not before.

Zeljan Rikalo

2018-11-23 09:43

developer   ~0112115

Brush.Color <> clNone should set Brush.Style to bsSolid afair.

Zeljan Rikalo

2018-11-23 09:43

developer   ~0112116

Have you tested with Qt5 64bit (cocoa) under mac ? If background is drawn under linux/windows then it could be Qt4 lib bug.

Alexander Koblov

2018-11-23 20:11

reporter   ~0112148

I tested with Qt5, same problem, background is not drawn. Same code works fine under Linux with Qt4, Qt5 so it is macOS specific Qt bug.

Zeljan Rikalo

2018-11-24 17:25

developer   ~0112173

Last edited: 2018-11-24 17:25

View 2 revisions

Ok, both Qt4 and Qt5 have {$IFDEF DARWIN} inside TQtDeviceContext.DrawText() (2 routines). That should be removed. I don't know why DrawText is forced to be transparent and when such commit arrives, must investigate a bit.
Workaround before fixing: Remove inside both routines:
 
{$IFDEF DARWIN}
OldBkMode := SetBkMode(TRANSPARENT)
{$ENDIF}

and

{$IFDEF DARWIN}
OldBkMode := SetBkMode(OldBkMode)
{$ENDIF}

and local variable OldBkMode.


Edit: qtobjects.pas unit

Zeljan Rikalo

2018-11-24 17:30

developer   ~0112174

r34202 commited by me, but revision log does not say too much about problem :)

Zeljan Rikalo

2018-11-25 13:14

developer   ~0112185

Please test and close if ok. Both Qt4 and Qt5 are fixed.

Alexander Koblov

2018-11-25 14:32

reporter   ~0112189

Works fine with Qt5 now. But still does not work with Qt4.

Zeljan Rikalo

2018-11-25 18:05

developer   ~0112193

Then it's problem with Qt4 libs. I don't use Qt4 on Mac anymore so cannot test.

Zeljan Rikalo

2018-11-25 18:17

developer   ~0112194

Try next (qtobjects.pas) - *if caller is use this one*:
in procedure TQtDeviceContext.drawText(x, y, w, h, flags: integer; s: PWideString);

RestoreTextColor;

{now trial to fix Qt4}
if getBKMode = OPAQUE then
  QPainter_fillRect(x, y, w, h, QPainter_brush(Widget));
// if QPainter_brush() does not fill anything try with vBrush.FHandle or vBackroundBrush.FHandle
{end of qt4 fix}

if Font.Angle <> 0 ...

Alexander Koblov

2018-11-26 17:15

reporter   ~0112209

TextOut calls procedure TQtDeviceContext.drawText(x: Integer; y: Integer; s: PWideString).

I made some experiments and get interesting results:

1. As I see QPainter_drawText draws background but with default control color. So fix looks like in attached patch.

2. If I change Form color from clDefault to any other color then background drawn with correct background color without patch.

So it works wrong when parent control color is clDefault.

Alexander Koblov

2018-11-26 17:15

reporter  

fix_qt4_darwin.patch (1,994 bytes)
Index: qtobjects.pas
===================================================================
--- qtobjects.pas	(revision 59665)
+++ qtobjects.pas	(working copy)
@@ -2822,6 +2822,10 @@
   To get a correct behavior we need to sum the text's height to the Y coordinate.
  ------------------------------------------------------------------------------}
 procedure TQtDeviceContext.drawText(x: Integer; y: Integer; s: PWideString);
+{$IFDEF DARWIN}
+var
+  OldBkMode: Integer;
+{$ENDIF}
 begin
   {$ifdef VerboseQt}
   Write('TQtDeviceContext.drawText TargetX: ', X, ' TargetY: ', Y);
@@ -2842,11 +2846,20 @@
 
   // The ascent is only applied here, because it also needs
   // to be rotated
+  {$IFDEF DARWIN}
+  if getBKMode = OPAQUE then
+    QPainter_fillRect(Widget, x, y - Metrics.ascent, Font.Metrics.width(s), Font.Metrics.height, QPainter_brush(Widget));
+
+  OldBkMode := SetBkMode(TRANSPARENT);
+  {$ENDIF}
   if Font.Angle <> 0 then
     QPainter_drawText(Widget, 0, Metrics.ascent, s)
   else
     QPainter_drawText(Widget, x, y, s);
-
+  {$IFDEF DARWIN}
+  SetBkMode(OldBkMode);
+  {$ENDIF}
+  
   RestorePenColor;
   
   // Restore previous angle
@@ -2869,6 +2882,10 @@
   Returns: Nothing
  ------------------------------------------------------------------------------}
 procedure TQtDeviceContext.drawText(x, y, w, h, flags: Integer; s: PWideString);
+{$IFDEF DARWIN}
+var
+  OldBkMode: Integer;
+{$ENDIF}
 begin
   {$ifdef VerboseQt}
   Write('TQtDeviceContext.drawText x: ', X, ' Y: ', Y,' w: ',w,' h: ',h);
@@ -2883,10 +2900,19 @@
   end;
 
   RestoreTextColor;
+  {$IFDEF DARWIN}
+  if getBKMode = OPAQUE then
+    QPainter_fillRect(Widget, x, y, w, h, QPainter_brush(Widget));
+
+  OldBkMode := SetBkMode(TRANSPARENT);
+  {$ENDIF}
   if Font.Angle <> 0 then
     QPainter_DrawText(Widget, 0, 0, w, h, Flags, s)
   else
     QPainter_DrawText(Widget, x, y, w, h, Flags, s);
+  {$IFDEF DARWIN}
+  SetBkMode(OldBkMode);
+  {$ENDIF}
   RestorePenColor;
 
   // Restore previous angle
fix_qt4_darwin.patch (1,994 bytes)

Zeljan Rikalo

2018-11-26 19:43

developer   ~0112210

In that case something else is buggy inside LCL or in Qt4LCL implementation.
getColorResolovingParent or GetDefaultColor(dctBrush) should be called somewhere in lcl when setting up brush.color from control which have Color = clDefault.
In any case I'll commit your patch since it's darwin and qt4 only.

Zeljan Rikalo

2018-11-26 19:44

developer   ~0112211

More: it's strange that QPainter_brush() contains valid color (as I can see in your patch) and BkMode is OPAQUE, but background isn't painted without fillRect()

Zeljan Rikalo

2018-11-26 19:49

developer   ~0112213

Please test and close if ok. Thanks for the patch. It looks that Qt4 lib does not take into account QPainter brush but control color if control color is clDefault, not QtLCL or LCL.

Issue History

Date Modified Username Field Change
2018-11-22 17:33 Alexander Koblov New Issue
2018-11-22 17:33 Alexander Koblov File Added: TextOutBug.zip
2018-11-22 18:06 jamie philbrook Note Added: 0112113
2018-11-23 09:43 Zeljan Rikalo Note Added: 0112115
2018-11-23 09:43 Zeljan Rikalo Assigned To => Zeljan Rikalo
2018-11-23 09:43 Zeljan Rikalo Status new => assigned
2018-11-23 09:43 Zeljan Rikalo LazTarget => -
2018-11-23 09:43 Zeljan Rikalo Note Added: 0112116
2018-11-23 09:43 Zeljan Rikalo Status assigned => feedback
2018-11-23 20:11 Alexander Koblov Note Added: 0112148
2018-11-23 20:11 Alexander Koblov Status feedback => assigned
2018-11-24 17:25 Zeljan Rikalo Note Added: 0112173
2018-11-24 17:25 Zeljan Rikalo Status assigned => feedback
2018-11-24 17:25 Zeljan Rikalo Note Edited: 0112173 View Revisions
2018-11-24 17:30 Zeljan Rikalo Note Added: 0112174
2018-11-25 13:14 Zeljan Rikalo Fixed in Revision => 59652
2018-11-25 13:14 Zeljan Rikalo Widgetset QT => QT, QT5
2018-11-25 13:14 Zeljan Rikalo Note Added: 0112185
2018-11-25 13:14 Zeljan Rikalo Status feedback => resolved
2018-11-25 13:14 Zeljan Rikalo Resolution open => fixed
2018-11-25 14:32 Alexander Koblov Note Added: 0112189
2018-11-25 14:32 Alexander Koblov Status resolved => assigned
2018-11-25 14:32 Alexander Koblov Resolution fixed => reopened
2018-11-25 18:05 Zeljan Rikalo Note Added: 0112193
2018-11-25 18:17 Zeljan Rikalo Note Added: 0112194
2018-11-26 17:15 Alexander Koblov Note Added: 0112209
2018-11-26 17:15 Alexander Koblov File Added: fix_qt4_darwin.patch
2018-11-26 19:43 Zeljan Rikalo Note Added: 0112210
2018-11-26 19:44 Zeljan Rikalo Note Added: 0112211
2018-11-26 19:49 Zeljan Rikalo Fixed in Revision 59652 => 59652,59667
2018-11-26 19:49 Zeljan Rikalo Note Added: 0112213
2018-11-26 19:49 Zeljan Rikalo Status assigned => resolved
2018-11-26 19:49 Zeljan Rikalo Resolution reopened => fixed
2018-12-08 17:00 Alexander Koblov Status resolved => closed