Lazarus

Programming => LCL => Topic started by: JD on July 09, 2013, 05:34:59 pm

Title: How does the ProgressBar's BarShowText property work?
Post by: JD on July 09, 2013, 05:34:59 pm
Hi there everyone,

I really don't understand how the ProgressBar's BarShowText property works. I want the progress bar to show percentage of completion or some text but the code below is not working at runtime. There are no errors but nothing shows in the progress bar!

Code: [Select]
ProgressBar1.BarShowText := True;
ProgressBar1.Caption := 'Working .....'

I can do this with other 3rd party progress bars but I want to see if it works with the standard progress bar so that I can do away with the others.

Thanks,

JD

Lazarus 1.1/FPC 2.6.2 svn 41998 on Win32

Title: Re: How does the ProgressBar's BarShowText property work?
Post by: howardpc on July 09, 2013, 07:44:23 pm
Likewise, I confirm that on Windows there seems to be no way that a progressbar's Caption is shown, whether the BarShowText property is True or False. I suppose it is a widgetset restriction.
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: edvard on February 10, 2014, 12:02:53 am
*Thread resurrection*

I was experimenting with DiskFree, DiskSize, and DiskAdd, making a simple disk usage thingie, when I thought it would be nice to have the TProgressBar show the percentage, or some custom text.  No banana.
...
 I suppose it is a widgetset restriction.
I see the results here (or lack thereof) are from running on Windows, but on Linux, there is something.  With Qt, the progress bar simply shows the percentage; "81%".  A bit minimal, but it'll do the job.  With GTK, it says "81 from [0-100] (81%)" which is a bit ugly.  I haven't been able to find in the documentation or searching the forum if there is a way to change the text, and I don't know enough about making custom components to make my own. 

Anybody have any ideas, or suggest a third-party progressbar that supports custom text?
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: edvard on February 10, 2014, 12:55:12 am
Ahh... grepping through the source tree I found lcl/include/progressbar.inc:
Quote
current design flaws:

  - I decided to support some gtk-specific properties in this class. This
    won't break Delphi compatibility but for 100% Delphi compatibility
    a better approach would be to derive another class.
    BTW: When porting to another widget library you can safely ignore

           FBarShowText
           FBarTextFormat

  - FBarTextFormat is a fixed string by now, hard-coded in the gtk-interface
  - lot's of properties are missing
  - I spend no thought on the usage of type integer for the range for the bar,
    maybe this can cause trouble some day (and already will when FMin < 0!)

Farther down:
Code: [Select]
constructor TCustomProgressBar.Create (AOwner : TComponent);
begin
  inherited Create(AOwner);
  fCompStyle := csProgressBar;
  FPosition  := 0;
  FStep := 10;
  FMin := 0;
  FMax := 100;
  FSmooth := False;
  FOrientation := pbHorizontal;
  FBarShowText := False;
  FBarTextFormat := '%v from [%l-%u] (=%p%%)';
  FStyle := pbstNormal;
  with GetControlClassDefaultSize do
    SetInitialBounds(0, 0, CX, CY);
end;

So, apparently the 'FBarTextFormat' property isn't shown or available, and is hard-coded.  However, the Qt interface apparently has something different in mind, but I couldn't find where either is defined except here in progressbar.inc, and changing the string did not work .  Just for giggles, I changed it to "Squirrel!!" and recompiled.  Still says "81 from [0-100] (81%)"

Any idea where this 'hard-coding' is located at so I can change it, or suggestions for making it settable in code?  I don't know enough to make my own components yet, but someday...
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: edvard on February 10, 2014, 01:25:40 am
...
Any idea where this 'hard-coding' is located at so I can change it,
...

Nevermind, I really should research a lot further before posting.   :\

I went grepping for BarShowText, and found it in lcl/interfaces/gtk2/gtk2wscomctrls.pp.  changed line 459 from
Code: [Select]
wText := Format('%d from [%d-%d] (%%p%%%%)', [Position, Min, Max]);to
Code: [Select]
wText := Format('%%p%%%%', [Position, Min, Max]);and recompiled Lazarus.  VoilĂ !

Not exactly the custom text function I'd like it to be, but at least it matches what shows using Qt.
Now, any suggestions on how to go about making that settable?
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: Cyrax on February 10, 2014, 02:54:16 am
You could change that text to point 'FBarTextFormat' variable. And maybe give a bug report (and attach patch) at here : http://bugs.freepascal.org/view_all_bug_page.php
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: zeljko on February 10, 2014, 07:25:02 am
With Qt , text depends on theme (MacOSX in this case)
https://qt-project.org/doc/qt-5/qprogressbar.html#textVisible-prop
Also , there's no way to change text, only format could be changed.
https://qt-project.org/doc/qt-5/qprogressbar.html#format-prop
For some custom progressbar it's best to create your own from TCustomControl or from TGraphicControl (depends on your needs).
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: JD on February 10, 2014, 10:16:03 am
@edvard

You could try the plShapeProgress component. I believe it is part of the components pack in the CodeTyphon derivative of Lazarus. The default shape is a circle (pie) but you can change it to a vertical bar or a horizontal bar. You can also change the fill colour. See screenshot.
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: edvard on February 11, 2014, 02:57:45 am
With Qt , text depends on theme (MacOSX in this case)
I did not know this.  Very good to know, thank you.
Quote
Also , there's no way to change text, only format could be changed.
I didn't know this either.  Apparently, Lazarus' Qt interface is hard coded to show the percentage.  Fine by me.
I at least figured out how to change the GTK default to match Qt, instead of the goofy default they have set.
I also figured out how to make BarTextFormat settable so you can just load a string into it, but since there's no equivalent for Qt, I decided against doing that.
Quote
For some custom progressbar it's best to create your own from TCustomControl or from TGraphicControl (depends on your needs).
Looks like I got me some learnin' to do...   8)

@edvard

You could try the plShapeProgress component. I believe it is part of the components pack in the CodeTyphon derivative of Lazarus. The default shape is a circle (pie) but you can change it to a vertical bar or a horizontal bar. You can also change the fill colour. See screenshot.
Very nice!  Thanks for the tip!  Big download for one component ;) but I'll try it anyway.  Maybe I can learn enough from the code to make my own basic progressbar.  8)
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: JanRoza on February 11, 2014, 11:25:38 pm
You could also take a look at ColorProgress from Wile64, a very complete progressbar component for Lazarus. You can find it at http://wile64.perso.neuf.fr/download/download.php?cat=4 (http://wile64.perso.neuf.fr/download/download.php?cat=4)
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: edvard on February 17, 2014, 11:54:13 am
Can't download ColorProgress, sorry.  The link goes to a 500 (internal server error) page.  :(
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: exdatis on February 17, 2014, 12:22:37 pm
Try this:
http://wiki.freepascal.org/BGRAControls#BGRAProgressBar
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: JanRoza on February 17, 2014, 01:08:40 pm
@Edvard: I'll upload the ColorProgress component this evening, I still have the archive lying around.
Title: Re: How does the ProgressBar's BarShowText property work?
Post by: JanRoza on February 20, 2014, 12:41:06 am
Here you have the colorprogress component. Enjoy!
TinyPortal © 2005-2018