[Resolved] Tlistview flicker problem if icon is updated lazarus / 31-LCL ---------------------------------------------------------------------- ArminLinder · 2017-11-25 18:39 Hi Lazarus/LCL/FPC experts, just for fun I have tried to make a TListView Icon spin. On my test form I have a lone TListView (ViewStyle := vsReport, RowSelect := true), and I added a bunch of images to my SmallImages list, the images [0..5] contain the pictures of my rotating symbol. To check things out I let the symbol spin using a timer: 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.Timer1Timer(Sender: TObject);   begin     if ListView1.Selected<>NIL then        ListView1.Selected.ImageIndex:=(ListView1.Selected.ImageIndex + 1) mod 5;   end;  The timer is set to 200ms, the principle works well, the icon of the selected row does indeed spin. But it seems like the LCL Listview redraws the whole row, not only the icon, causing the whole selected row flicker annoyingly. Does anyone know a way to reduce the flicker, or at least modify the repaint behaviour in such a way that only the icon flickers, but not the entire row?? Thx, Armin. (Lazarus 1.6.4 on Windows 7/Windows 10) ---------------------------------------------------------------------- jamie · 2017-11-25 20:47 You could experiment a little with the Region property of the Canvas. ListView1.Canvas.Region := SomewhereRegion  The Region has a ClicpRect in it that limits the areas of painting. The idea is to set it to the area of where the Images are updating.  When you do this, all other areas should be ignored.  Also, there is a property called Clipping:Boolean;  Give it a go. ---------------------------------------------------------------------- ASerge · 2017-11-25 20:50 Quote from: Nimral on November 25, 2017, 07:39:53 pmOn my test form I have a lone TListView (ViewStyle := vsReport, RowSelect := true), and I added a bunch of images to my SmallImages list, the images [0..5] contain the pictures of my rotating symbol. ...But it seems like the LCL Listview redraws the whole row, not only the icon, causing the whole selected row flicker annoyingly. Windows 7, Lazarus 1.8 RC5. I do not see flicker with or without themes. The code in Lazarus only changes the image: 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 TListItem.SetImageIndex(const AValue: TImageIndex);begin  if AValue = FImageIndex then     Exit;  FImageIndex := AValue;  if WSUpdateAllowed then     TWSCustomListViewClass(FOwner.FOwner.WidgetSetClass).ItemSetI mage(FOwner.FOwner, GetIndex, Self, 0, FImageIndex);end; class procedure TWin32WSCustomListView.ItemSetImage(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex, AImageIndex: Integer);var  lvi: TLvItem;begin  if not WSCheckHandleAllocated(ALV, 'ItemSetImage') then     Exit;  lvi.Mask := LVIF_IMAGE;  // <- ONLY IMAGE  lvi.iItem := AIndex;  lvi.iSubItem := ASubIndex;  lvi.iImage := AImageIndex;  ListView_SetItem(ALV.Handle, lvi);end;By the way, if there are 6 images ([0..5]), then it's better to use them all: ...) mod 6. ---------------------------------------------------------------------- jamie · 2017-11-26 01:06 Maybe ListView1.DoubleBuffered := True;  Will help? ---------------------------------------------------------------------- ArminLinder · 2017-11-26 10:00 Hi Jamie&Serge, thank you for your quick replies. See attached video --> it DOES flicker :-). DoubleBuffer is already on, doesn't seem to change anything. You think an upgrade to 1.8 may help, has the LCL code been worked over? Armin. Here is the complete source I use for testing, is a snipped from a larger project, so don't wonder about the initialization routine: 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 unit unit2; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,  ComCtrls, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    ImageList1: TImageList;    ListView1: TListView;    Timer1: TTimer;    procedure Button2Click(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure ListView1Click(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.ListView1Click(Sender: TObject); beginend; procedure TForm1.Timer1Timer(Sender: TObject);begin  if ListView1.Selected<>NIL then     ListView1.Selected.ImageIndex:= (ListView1.Selected.ImageIndex + 1) mod 5;end; procedure TForm1.Button2Click(Sender: TObject); begin     Timer1.Enabled := not Timer1.Enabled;end; procedure TForm1.FormCreate(Sender: TObject); var i : integer;    ListItem: TListItem;    Col:TListColumn; begin  With ListView1 do   begin   DoubleBuffered := true;   RowSelect := true;   if Columns.Count = 0 then      begin        Col := Columns.Add;        Col.Caption := '';      Col.AutoSize := true;        Col := Columns.Add;        Col.Caption := '1st Subitem';        Col.Width := 100;        Col := Columns.Add;        Col.Caption := '2nd SubItem';        Col.Width := 100;      end;   clear;   for i := 0 to 100 do     begin       ListItem := Items.Add;       ListItem.ImageIndex:=1;       ListItem.SubItems.Add('Item ' + IntToStr(i));       ListItem.SubItems.Add('SubItem ' + IntToStr(i));     end;   end;end; end. ---------------------------------------------------------------------- balazsszekely · 2017-11-26 10:13 @Nimral You should also attach the small test project, apparently there is an ImageList in your project.  Also tell us when the flicker occurs. ---------------------------------------------------------------------- ArminLinder · 2017-11-26 13:25 Quote from: GetMem on November 26, 2017, 11:13:59 am@Nimral You should also attach the small test project, apparently there is an ImageList in your project.  Also tell us when the flicker occurs. Hi GetMem, --> Attachment! Itemlist is pretty straightforward, I took an icon and made a few rotated versions of it. Not even the whole 360° yet, wanted to test first. Armin. ---------------------------------------------------------------------- balazsszekely · 2017-11-26 15:56 @Nimral Testing environment: 1. Win7(64 bit), Lazarus Trunk, FPC 3.0.2 2. Linux Mint Cinnamon(64 bit), Lazarus Trunk, FPC Trunk 3. XP(32 bit), Lazarus 1.8RC5, FPC 3.0.4 I see no flicker whatsoever. The icons are rotating nicely. ---------------------------------------------------------------------- ArminLinder · 2017-11-26 16:43 Hi GetMem, Thanks for your feedback. Seems I need to look deeper into that issue tomorrow. As you see in my video, there definitiely is a flicker problem, but if you say, it's not standard LCL behaviour, there must be another reason, why it appears on my system. I'll put my demo code through various demo machines tomorrow, let's see if there is some dependency on graphics hardware or driver. Greetz, Armin. ---------------------------------------------------------------------- balazsszekely · 2017-11-26 19:00 Quotebut if you say, it's not standard LCL behaviour, there must be another reason, why it appears on my system.All I'm saying is I cannot reproduce the issue in a newer version of Lazarus. The bug most likely was already fixed. ---------------------------------------------------------------------- ArminLinder · 2017-11-27 07:16 Hi guys, I put the program through some other computers I had lying around, as well as through several virtual machines (MS Remote Desktop), and the problem does not appear on any system but my development computer. I tried both 1.6.4 and 1.8 RC4. Since my development system is a virtualized (VMWare 12) system I suspect that it is most likely a problem with the VMWare VGA driver. This is somewhat surprising, I usually don't have any notable screen refresh problems in VMware, that's why it didn't come to my mind to suspect a problem with the virtualization. Sorry guys for having bugged you, and thanks for your helpful hints. Armin.