TreeView: Conflict between OnCustomDrawItem and HotTracking lazarus / 31-LCL ---------------------------------------------------------------------- EganSolo · 2025-06-04 07:05 I'm using a treeview component and assigned images to the nodes. Sadly, that hides the collapse/expand signs. Instead, I've implemented the OnCustomDrawItem to bold a node if it has children. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TOptionsForm.TvCustomDrawItem(Sender         : TCustomTreeView ;                                      Node           : TTreeNode       ;                                      State          : TCustomDrawState;                                        var DefaultDraw: Boolean         );begin  If Node.Count > 0  then Sender.Canvas.Font.Style := [fsBold]  else Sender.Canvas.Font.Style := [];   end;   This works except if hot tracking is enabled, in which case, the bolding is ignored when the mouse hovers over the node and the text is underlined. Is the behavior hardwired in TTreeview, or is there a straightforward way to override it? ---------------------------------------------------------------------- Jurassic Pork · 2025-06-04 08:53 Hello, with hotTracking  , you can change the color of the text of a node but not attributes because hotTrack force underline and some other attributes of the font. Example : code (don't forget to put types in the uses ) : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.tv_eg1CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;  State: TCustomDrawState; var DefaultDraw: Boolean);var  R: TRect;begin   R := Node.DisplayRect(true);  if (PtInRect(R, sender.ScreenToClient(Mouse.CursorPos))) then  begin    If Node.Text = 'Root' then       begin         Sender.Canvas.Font.Color := clBlue;     end;    If Node.Text = 'Node1' then   Sender.Canvas.Font.Color := clRed;    If Node.Text = 'Node2' then   Sender.Canvas.Font.Color := clAqua;    If Node.Text = 'Node3' then   Sender.Canvas.Font.Color := clLime;  end;end; Result in Attachment. Friendly, J.P ---------------------------------------------------------------------- wp · 2025-06-04 08:58 Custom-drawing of the treeview has been quite buggy; this was fixed recently, hot-tracking is done by the theme-services now, but underlining is still possible when the theme-draw options is removed. Since this required some breaking changes it did not make it into v4.0 (https://wiki.freepascal.org/Lazarus_5.0_release_notes#TTreeView). Working with a non-trunk version of Lazarus you can use the following workaround: Turn hot-tracking off and do it yourself. For this purpose you must redraw the tree with every mouse move when the mouse is over a different node. And in the OnCustomDrawItem handler you check whether the currently painted node is the same is the node under the mouse, and in this case you turn on underlining: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TForm1 = class(TForm)    TreeView1: TTreeView;    procedure TreeView1CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;    State: TCustomDrawState; var DefaultDraw: Boolean);    procedure TreeView1MouseMove(Sender: TObject; Shift: TShiftState; X,      Y: Integer);  private    FNodeUnderCursor: TTreeNode;    FPrevNodeUnderCursor: TTreeNode;  public   end; procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);begin  If Node.Count > 0  then Sender.Canvas.Font.Style := [fsBold]  else Sender.Canvas.Font.Style := [];   if Node = FNodeUnderCursor then    Sender.Canvas.Font.Style := Sender.Canvas.Font.Style + [fsUnderline];end; procedure TForm1.TreeView1MouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);begin  FNodeUnderCursor := (Sender as TTreeView).GetNodeAt(X, Y);  if FNodeUnderCursor <> FPrevNodeUnderCursor then  begin    TreeView1.Invalidate;    FPrevNodeUnderCursor := FNodeUnderCursor;  end;end; In the trunk version your original code, however, would not work inspite of the customdrawing repair. This is because you set the Canvas.Font.style to [fsBold] or [] - and this removes the underlining state. If you change it as follows it would work in trunk, too: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView; Node:  TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);begin  If Node.Count > 0  then Sender.Canvas.Font.Style := Sender.Canvas.Font.Style + [fsBold]  else Sender.Canvas.Font.Style := Sender.Canvas.Font.Style - [fsBold];end; ---------------------------------------------------------------------- EganSolo · 2025-06-07 00:24 wp: Thanks a lot! I'll follow through and report back!