View Issue Details

IDProjectCategoryView StatusLast Update
0036367LazarusLCLpublic2019-11-27 11:42
ReporterLoryn Brendes Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
OSUbuntu 
Product Version2.0.4 
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

Activities

Loryn Brendes

2019-11-27 11:42

reporter  

listviewmain.lfm (1,148 bytes)   
object MainForm: TMainForm
  Left = 412
  Height = 240
  Top = 155
  Width = 320
  Caption = 'MainForm'
  ClientHeight = 240
  ClientWidth = 320
  LCLVersion = '2.0.4.0'
  object ListView1: TListView
    Left = 0
    Height = 190
    Top = 0
    Width = 320
    Align = alClient
    Columns = <    
      item
        Caption = 'Col 0'
      end    
      item
        Caption = 'Col 1'
      end    
      item
        Caption = 'Col 2'
        Width = 205
      end>
    Items.LazData = {
      9E00000003000000FFFFFFFFFFFFFFFFFFFFFFFF02000000060000006C696E65
      203004000000436F6C3104000000436F6C32FFFFFFFFFFFFFFFFFFFFFFFF0200
      0000060000006C696E65203104000000436F6C3104000000436F6C32FFFFFFFF
      FFFFFFFFFFFFFFFF02000000060000006C696E65203204000000436F6C310400
      0000436F6C32FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
    }
    RowSelect = True
    TabOrder = 0
    ViewStyle = vsReport
    OnCustomDrawItem = ListView1CustomDrawItem
    OnCustomDrawSubItem = ListView1CustomDrawSubItem
  end
  object Panel1: TPanel
    Left = 0
    Height = 50
    Top = 190
    Width = 320
    Align = alBottom
    TabOrder = 1
  end
end
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)   
program TestListView;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, ListViewMain
  { you can add units after this };

{$R *.res}

begin
  RequireDerivedFormResource:=True;
  Application.Scaled:=True;
  Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

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