Recent

Author Topic: How does the ProgressBar's BarShowText property work?  (Read 15294 times)

JD

  • Hero Member
  • *****
  • Posts: 1755
How does the ProgressBar's BarShowText property work?
« 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

« Last Edit: July 09, 2013, 05:42:50 pm by JD »
Windows (10, 7) - Lazarus 2.0RC3/FPC 3.2, NewPascal, Delphi

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

howardpc

  • Hero Member
  • *****
  • Posts: 3043
Re: How does the ProgressBar's BarShowText property work?
« Reply #1 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.

edvard

  • Full Member
  • ***
  • Posts: 165
Re: How does the ProgressBar's BarShowText property work?
« Reply #2 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?
All children left unattended will be given a mocha and a puppy.

Debian 'Testing' 64-bit | Xfce 4.12 | FreePascal 3.0 + Lazarus 1.6.2, GTK2+ and Qt

edvard

  • Full Member
  • ***
  • Posts: 165
Re: How does the ProgressBar's BarShowText property work?
« Reply #3 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...
All children left unattended will be given a mocha and a puppy.

Debian 'Testing' 64-bit | Xfce 4.12 | FreePascal 3.0 + Lazarus 1.6.2, GTK2+ and Qt

edvard

  • Full Member
  • ***
  • Posts: 165
Re: How does the ProgressBar's BarShowText property work?
« Reply #4 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?
All children left unattended will be given a mocha and a puppy.

Debian 'Testing' 64-bit | Xfce 4.12 | FreePascal 3.0 + Lazarus 1.6.2, GTK2+ and Qt

Cyrax

  • Hero Member
  • *****
  • Posts: 738
Re: How does the ProgressBar's BarShowText property work?
« Reply #5 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

zeljko

  • Hero Member
  • *****
  • Posts: 1050
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How does the ProgressBar's BarShowText property work?
« Reply #6 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).

JD

  • Hero Member
  • *****
  • Posts: 1755
Re: How does the ProgressBar's BarShowText property work?
« Reply #7 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.
« Last Edit: February 10, 2014, 10:21:22 am by JD »
Windows (10, 7) - Lazarus 2.0RC3/FPC 3.2, NewPascal, Delphi

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

edvard

  • Full Member
  • ***
  • Posts: 165
Re: How does the ProgressBar's BarShowText property work?
« Reply #8 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)
All children left unattended will be given a mocha and a puppy.

Debian 'Testing' 64-bit | Xfce 4.12 | FreePascal 3.0 + Lazarus 1.6.2, GTK2+ and Qt

JanRoza

  • Hero Member
  • *****
  • Posts: 522
    • http://www.silentwings.nl
Re: How does the ProgressBar's BarShowText property work?
« Reply #9 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
OS: Windows 10 (64 bit) / Ubuntu 19.04 (64 bit)
Laz: Lazarus 2.0.2 FPC 3.0.4 i386-win32-win32/win64

edvard

  • Full Member
  • ***
  • Posts: 165
Re: How does the ProgressBar's BarShowText property work?
« Reply #10 on: February 17, 2014, 11:54:13 am »
Can't download ColorProgress, sorry.  The link goes to a 500 (internal server error) page.  :(
All children left unattended will be given a mocha and a puppy.

Debian 'Testing' 64-bit | Xfce 4.12 | FreePascal 3.0 + Lazarus 1.6.2, GTK2+ and Qt

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis

JanRoza

  • Hero Member
  • *****
  • Posts: 522
    • http://www.silentwings.nl
Re: How does the ProgressBar's BarShowText property work?
« Reply #12 on: February 17, 2014, 01:08:40 pm »
@Edvard: I'll upload the ColorProgress component this evening, I still have the archive lying around.
OS: Windows 10 (64 bit) / Ubuntu 19.04 (64 bit)
Laz: Lazarus 2.0.2 FPC 3.0.4 i386-win32-win32/win64

JanRoza

  • Hero Member
  • *****
  • Posts: 522
    • http://www.silentwings.nl
Re: How does the ProgressBar's BarShowText property work?
« Reply #13 on: February 20, 2014, 12:41:06 am »
Here you have the colorprogress component. Enjoy!
OS: Windows 10 (64 bit) / Ubuntu 19.04 (64 bit)
Laz: Lazarus 2.0.2 FPC 3.0.4 i386-win32-win32/win64