Sounds reasonable. Because if the mouse pointer is no longer hovering on the window, it won't be monitored.
But it doesn't explain why on my test it still able to trigger OnMouseLeave event but only at very low rate.
Okay, let me explain what I actually want to do. I want to customize TDrawGrid appearance using OnCellDraw and OnPrepareCanvas. It worked, but I got mouse hovering problem. I want the cells will be automatically highlighted when the mouse hovering on it and the highlight is removed when the mouse pointer if not on the cell.
Below is the code, to make it simple I used TStringGrid and removed all unnecessary things:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Forms, Graphics, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
begin
if gdHot in aState then
(sender as TStringGrid).Canvas.Brush.Color := clRed;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Options := StringGrid1.Options + [goHeaderHotTracking];
end;
end.
Try to move your mouse pointer to highlight the cells and slowly move it outside. It should work correctly, but try it again with moving your mouse very quickly. The highlight won't be removed.
What I thought is perhaps because the mouse pointer movement is too fast, the grid doesn't properly detected the mouse leaving (from grid to the form). So, I think to solve it by adding code on TForm.OnMouseLeave to remove the grid highlight.
I also provided the downloadable code (test.zip) for you to test. Does it happen on Linux GTK2 only or also on other systems?