View Issue Details

IDProjectCategoryView StatusLast Update
0036367LazarusLCLpublic2019-11-27 11:42
ReporterLoryn BrendesAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformOSUbuntuOS Version18.04.3
Product Version2.0.4Product Build 
Target VersionFixed in Version 
Summary0036367: ListView with colored background, font not working under Linux
DescriptionForm with TListView and events CustomDrawItem, CustomDrawSubItem
Events are fired but selected colors have no effect.
Test project works under Windows.
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetGTK 2
Attached Files
  • listviewmain.lfm (1,148 bytes)
  • listviewmain.pas (1,632 bytes)
    unit ListViewMain;
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, ComCtrls,
      ExtCtrls;
    
    type
    
      { TMainForm }
    
      TMainForm = class(TForm)
        ListView1: TListView;
        Panel1: TPanel;
        procedure ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem;
          State: TCustomDrawState; var DefaultDraw: Boolean);
        procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
          Item: TListItem; SubItem: Integer; State: TCustomDrawState;
          var DefaultDraw: Boolean);
      private
    
      public
    
      end;
    
    var
      MainForm: TMainForm;
    
    implementation
    
    {$R *.lfm}
    
    { TMainForm }
    
    procedure TMainForm.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    begin
      // Col 0 with colored background
      case Item.Index mod 3 of
        0: begin
          Sender.Canvas.Brush.Color := clYellow;
          Sender.Canvas.Font.Color := clBlack;
        end;
        1: begin
          Sender.Canvas.Brush.Color := clRed;
          Sender.Canvas.Font.Color := clYellow;
        end;
        2: begin
          Sender.Canvas.Brush.Color := clBlue;
          Sender.Canvas.Font.Color := clWhite;
        end;
      end;
    end;
    
    procedure TMainForm.ListView1CustomDrawSubItem(Sender: TCustomListView;
      Item: TListItem; SubItem: Integer; State: TCustomDrawState;
      var DefaultDraw: Boolean);
    begin
      // columns with white background
      Sender.Canvas.Brush.Color := clWhite;
    
      // columns with colored font
      case SubItem of
        1: Sender.Canvas.Font.Color := clRed;
        2: Sender.Canvas.Font.Color := clBlue;
      else Sender.Canvas.Font.Color := clBlack;
      end;
    end;
    
    end.
    
    
    listviewmain.pas (1,632 bytes)
  • TestListView.lpr (404 bytes)

Activities

Loryn Brendes

2019-11-27 11:42

reporter  

listviewmain.lfm (1,148 bytes)
listviewmain.pas (1,632 bytes)
unit ListViewMain;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, ComCtrls,
  ExtCtrls;

type

  { TMainForm }

  TMainForm = class(TForm)
    ListView1: TListView;
    Panel1: TPanel;
    procedure ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem;
      State: TCustomDrawState; var DefaultDraw: Boolean);
    procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
      Item: TListItem; SubItem: Integer; State: TCustomDrawState;
      var DefaultDraw: Boolean);
  private

  public

  end;

var
  MainForm: TMainForm;

implementation

{$R *.lfm}

{ TMainForm }

procedure TMainForm.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  // Col 0 with colored background
  case Item.Index mod 3 of
    0: begin
      Sender.Canvas.Brush.Color := clYellow;
      Sender.Canvas.Font.Color := clBlack;
    end;
    1: begin
      Sender.Canvas.Brush.Color := clRed;
      Sender.Canvas.Font.Color := clYellow;
    end;
    2: begin
      Sender.Canvas.Brush.Color := clBlue;
      Sender.Canvas.Font.Color := clWhite;
    end;
  end;
end;

procedure TMainForm.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  // columns with white background
  Sender.Canvas.Brush.Color := clWhite;

  // columns with colored font
  case SubItem of
    1: Sender.Canvas.Font.Color := clRed;
    2: Sender.Canvas.Font.Color := clBlue;
  else Sender.Canvas.Font.Color := clBlack;
  end;
end;

end.

listviewmain.pas (1,632 bytes)
TestListView.lpr (404 bytes)

Issue History

Date Modified Username Field Change
2019-11-27 11:42 Loryn Brendes New Issue
2019-11-27 11:42 Loryn Brendes File Added: listviewmain.lfm
2019-11-27 11:42 Loryn Brendes File Added: listviewmain.pas
2019-11-27 11:42 Loryn Brendes File Added: TestListView.lpr