Recent

Author Topic: ListView with progress bars  (Read 9993 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
ListView with progress bars
« on: December 09, 2010, 07:39:37 pm »
Hi,

I'm trying to draw ProgressBar on ListView items. I can't find any tutorial for lazarus TListView so I use this:
http://delphi.about.com/library/weekly/aa053105a.htm
But it doesn't work. No progress bar is showing. Is it a bug or Lazarus have different concept for this?

Regards

Ubuntu 10.10 64bit, GTK 2. Lazarus 0.9.29 from SVN, revision 28558. FPC 2.5.1 from SVN, revision 16476

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: ListView with progress bars
« Reply #1 on: March 31, 2015, 06:49:23 am »
Really late, but it's to help those who have this problem...

Works in the following way...

Add two Buttons and one ListView

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  r: TRect;
  pb: TProgressBar;
begin
  Listview1.ViewStyle         := vsReport;
  Listview1.Columns.Add.Width := Round(Listview1.Width / 4);
  Listview1.Columns.Add.Width := Round(Listview1.Width - Listview1.columns[0].Width) - 22;
  Listview1.Items.Add.Caption := 'Text';

  r := Listview1.Items[0].DisplayRect(drBounds);
  r.Left  := r.Left + Listview1.columns[0].Width;
  r.Right := r.Left + Listview1.columns[1].Width;

  pb := TProgressBar.Create(Self);
  pb.Parent := Listview1;
  pb.BoundsRect := r;
  pb.Position := 5;
  Listview1.Items[0].Data := pb;

end;

// Change the ProgressBar Position
// ProgressBar Position ändern

procedure TForm1.Button2Click(Sender: TObject);
var
  pb: TProgressBar;
begin
  pb := TProgressBar(Listview1.Items[0].Data);
  pb.StepIt;
end;


zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: ListView with progress bars
« Reply #2 on: March 31, 2015, 11:11:53 am »
Isn't it better to use OwnerDraw, and paint themed progressbar inside listview item ?
With your solution you must think of scrolling too (each visible progressbar you must move manually when listview is scrolled).

darkdata

  • New Member
  • *
  • Posts: 13
Re: ListView with progress bars
« Reply #3 on: March 31, 2015, 08:31:00 pm »
Here are some delphi examples of drawing it:

http://stackoverflow.com/questions/7044125/delphi-draw-own-progress-bar-in-list-view

I haven't done it with LCL yet but I am interested.

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: ListView with progress bars
« Reply #4 on: March 31, 2015, 10:27:20 pm »
Works under Windows. The unit 'windows' is used though, so I guess its not cross platform?

Here are some delphi examples of drawing it:

http://stackoverflow.com/questions/7044125/delphi-draw-own-progress-bar-in-list-view

I haven't done it with LCL yet but I am interested.
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: ListView with progress bars
« Reply #5 on: August 26, 2015, 12:06:08 pm »
I've found a cute way to show percentages in full color, using the event BeforeCellPaint on a TVirtualStringTree. This colored progress is not affected by the Windows theme, looks exactly like in the attached image on Windows XP, 7, 8 or 10 (not tested on linux).

My code is a mess, apologize for not providing demo at this time. In a few days I'll do that.

 

TinyPortal © 2005-2018