delphitreeviewvcl-styles

How to make TTreeView not highlight all nodes when disabled?


I'm using VCL Styles in my application, specifically using "Windows 10 dark" which is black with white text. Then I have a TTreeView control, which shows perfectly fine. However, when the user enters "Edit" mode, I disable the TTreeView, and when it's disabled, it looks extremely ugly, showing every node highlighted.

enter image description here

How do I make it so that it shows normal when disabled, without highlighting all nodes, but just highlighting the current selected node only?

NOTE: I'm trying to avoid custom drawing. While that looks the necessary course of action, I'm really not aiming to make this some super complex solution, so alternatives such as the virtual tree view are not in the picture.


EDIT

enter image description here

I've tried to implement the recommended "solution", but to no avail. Here's what I added:

procedure TfrmTopics.TopicTreeAdvancedCustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
  var PaintImages, DefaultDraw: Boolean);
begin
  inherited;
  if (not TopicTree.Enabled) and
    (GetWindowTheme(TopicTree.Handle) = 0) and (Stage = cdPrePaint) then
  begin
    DefaultDraw:= True; // False; //Tried both ways...
    TopicTree.Canvas.Brush.Color := TopicTree.Color;
    TopicTree.Canvas.Font.Color := clWhite; 
    TopicTree.Canvas.Pen.Color:= clWhite;
  end;
end;

It only draws the currently selected node's text - not the rest. I'm assuming it has to do with the dark style and overriding colors...

Which, by the way, the TTreeView.StyleElements has seFont and seClient disabled.


Solution

  • Use VCL Styles Utils components from: https://github.com/RRUZ/vcl-styles-utils

    Include Vcl.Styles.Hooks in your project