Recent

Author Topic: how to show hints NOT also at child elements  (Read 12475 times)

Muso

  • Sr. Member
  • ****
  • Posts: 356
how to show hints NOT also at child elements
« on: July 21, 2021, 04:57:04 am »
I have TGroupBox which contains a TRadioGroup. The TGroupBox has a hint and the hint should be shown. However, when the user is with the mouse over the TRadioGroup, no hint should be shown. How can I achieve this?

I am asking because whatever settings I tried, the hint of the TGroupBox also appears for the TRadioGroup.

Attached is a small demo program showing the issue.

Bart

  • Hero Member
  • *****
  • Posts: 5265
    • Bart en Mariska's Webstek
Re: how to show hints NOT also at child elements
« Reply #1 on: July 22, 2021, 12:03:54 am »
Set RadioGroup's ParentShowHint to False?

Bart

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: how to show hints NOT also at child elements
« Reply #2 on: July 22, 2021, 12:35:33 am »
Set RadioGroup's ParentShowHint to False?

That won't work. Logically enough, since it only means that ShowHint is set to the same value the parent has. The only way to prevent the RadioGroup (or any other child) from showing the parent's hint is to set a Hint of its own for it and set its ShowHint to True.

Of course, then it will show this hint but that's better than showing the parent's, which doesn't apply to this control.

One would think that setting both ParentShowHint and ShowHint to False would work too (and display nothing), but it doesn't: in that case the parent is interrogated and, if all is set its Hint will be shown.
« Last Edit: July 22, 2021, 12:38:47 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

balazsszekely

  • Guest
Re: how to show hints NOT also at child elements
« Reply #3 on: July 22, 2021, 06:47:13 am »
@Muso
Quote
However, when the user is with the mouse over the TRadioGroup, no hint should be shown. How can I achieve this?
Set property ShowHint for the RadioGroup to True,  then:

Code: Pascal  [Select][+][-]
  1.  TForm1 = class(TForm)
  2.   //..
  3.     procedure FormCreate(Sender: TObject);
  4.  private
  5.    procedure OnShowHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
  6.  public
  7.   end;  
  8.        
  9. procedure TForm1.FormCreate(Sender: TObject);
  10. begin
  11.   Application.OnShowHint := @OnShowHint;
  12. end;
  13.  
  14. procedure TForm1.OnShowHint(var HintStr: string; var CanShow: Boolean;
  15.   var HintInfo: THintInfo);
  16. begin
  17.   CanShow := not ((HintInfo.HintControl is TRadioButton) or (HintInfo.HintControl is TRadioGroup));
  18. end;  

If you have multiple RadioGroups, the above method will silence them all, but then you can play with the Tag property to enable/disable hint for a particular RadioGroup.
« Last Edit: July 22, 2021, 07:01:17 am by GetMem »

Bart

  • Hero Member
  • *****
  • Posts: 5265
    • Bart en Mariska's Webstek
Re: how to show hints NOT also at child elements
« Reply #4 on: July 22, 2021, 01:12:43 pm »
One would think that setting both ParentShowHint and ShowHint to False would work too (and display nothing), but it doesn't:

That was what I imagined as well.
I just checked D7, and it behaves the same.

Bart

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: how to show hints NOT also at child elements
« Reply #5 on: July 22, 2021, 02:05:13 pm »
Set property ShowHint for the RadioGroup to True,  then:
...
If you have multiple RadioGroups, the above method will silence them all, but then you can play with the Tag property to enable/disable hint for a particular RadioGroup.

Thanks. Unfortunately it doesn't work for me, see my attached demo program with your solution.

Nevertheless, I have in total 58 (sic!) radio groups in my program. It would be a nightmare to handle them differently that some show a hint, some not.

In general, I need a solution in which the child of a groupbox does not show any hint, nevertheless if the groupbox itself shows a hint or not.
It seems this is not possible.
The question is now, could this be implemented to the LCL for future or not. If yes, I would like to open an enhancement issue in the bugtracker.

balazsszekely

  • Guest
Re: how to show hints NOT also at child elements
« Reply #6 on: July 22, 2021, 02:34:34 pm »
Quote
Thanks. Unfortunately it doesn't work for me, see my attached demo program with your solution.
You're welcome! It works if you set Pump1DirectionRG1's ShowHint property to true, as I mentioned in my previous post.

Quote
Nevertheless, I have in total 58 (sic!) radio groups in my program. It would be a nightmare to handle them differently that some show a hint, some not.
You don't have to handle it differently for all 58 radio group. If you don't want to show hint for a particular radiogroup, just set Tag to 1 and add that condition to:
Code: Pascal  [Select][+][-]
  1. CanShow := not ((HintInfo.HintControl is TRadioButton) or (HintInfo.HintControl is TRadioGroup));


Quote
In general, I need a solution in which the child of a groupbox does not show any hint, nevertheless if the groupbox itself shows a hint or not.
It seems this is not possible. The question is now, could this be implemented to the LCL for future or not. If yes, I would like to open an enhancement issue in the bugtracker.
You could file a bugreport, but if delphi behaves in a similar way, I don't think it will be changed(maybe I'm wrong here).

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: how to show hints NOT also at child elements
« Reply #7 on: July 22, 2021, 02:53:46 pm »
I think you could define a "wild-card hint" meaning "don't show this hint". Suppose all components for which you do not want to see a hint, no matter of the child-parent-relationship, have the Hint text '*'. Then the Application.OnHint could check for this text and turn off the hint if it matches. Since Application.OnHint is application-wide, all your hints are handled with that same handler.

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: how to show hints NOT also at child elements
« Reply #8 on: July 22, 2021, 03:25:08 pm »
You're welcome! It works if you set Pump1DirectionRG1's ShowHint property to true, as I mentioned in my previous post.

Opps, sorry for my mistake.

Quote
You don't have to handle it differently for all 58 radio group. If you don't want to show hint for a particular radiogroup, just set Tag to 1 and add that condition to:

OK, got it.

Quote
Quote
In general, I need a solution in which the child of a groupbox does not show any hint, nevertheless if the groupbox itself shows a hint or not.
It seems this is not possible. The question is now, could this be implemented to the LCL for future or not. If yes, I would like to open an enhancement issue in the bugtracker.
You could file a bugreport, but if delphi behaves in a similar way, I don't think it will be changed(maybe I'm wrong here).

I don't know how Delphi behaves. Can one have there a hing for the GroupBox but no hint for a child of this GroupBox?

balazsszekely

  • Guest
Re: how to show hints NOT also at child elements
« Reply #9 on: July 22, 2021, 08:02:24 pm »
@Muso
Quote
I don't know how Delphi behaves. Can one have there a hing for the GroupBox but no hint for a child of this GroupBox?
See Bart's comment above. :)

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: how to show hints NOT also at child elements
« Reply #10 on: July 22, 2021, 08:34:10 pm »
@Muso
Quote
I don't know how Delphi behaves. Can one have there a hing for the GroupBox but no hint for a child of this GroupBox?
See Bart's comment above. :)

I don't understand. If "D7" means Delphi 7, this version is from 2002, so almost 20 years old. If it means Delphi 2007, this is still 14 years old.
I think such old versions cannnot be the benchmark for the development.

balazsszekely

  • Guest
Re: how to show hints NOT also at child elements
« Reply #11 on: July 22, 2021, 08:59:41 pm »
@Muso
Quote
I don't understand. If "D7" means Delphi 7
Yes Delphi 7.

Quote
this version is from 2002, so almost 20 years old. If it means Delphi 2007, this is still 14 years old.
I think such old versions cannnot be the benchmark for the development.
OK, fair enough. I just tested with the latest Delphi(10.4.4 - Sydney)...same behaviour.

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: how to show hints NOT also at child elements
« Reply #12 on: July 22, 2021, 10:56:24 pm »
I don't understand. If "D7" means Delphi 7, this version is from 2002, so almost 20 years old. If it means Delphi 2007, this is still 14 years old.
I think such old versions cannnot be the benchmark for the development.
I don't agree. Delphi 7 was one of the last versions before the change from ANSI to UTF16 strings. Because Lazarus uses UTF8 strings it is closer to D7 than to the current version. Furthermore, Delphi is fairly conservative regarding breaking changes, so most of the features of Delphi 7 are still valid today. And Delphi did not introduce significant changes to the VCL (the counterpart of our LCL) since the XE series, most of the changes are in Firemonkey which Lazarus does not support at all. Therefore, D7 is a good basis for a reference version.

Bart

  • Hero Member
  • *****
  • Posts: 5265
    • Bart en Mariska's Webstek
Re: how to show hints NOT also at child elements
« Reply #13 on: July 22, 2021, 11:47:18 pm »
I don't understand. If "D7" means Delphi 7, this version is from 2002, so almost 20 years old. If it means Delphi 2007, this is still 14 years old.
I think such old versions cannnot be the benchmark for the development.

It is Delphi 7.
Because thats the only version I have (before that I had Delphi 3 Pro).
Lazarus started out trying to be compatible with Delphi 7.
Bu besides that, anyone with a newer version can test if this behaviour is still present.
If not, then we should change it as well.
(To me, the behaviour feels like a bug.)

Bart

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: how to show hints NOT also at child elements
« Reply #14 on: July 22, 2021, 11:54:17 pm »
Bu besides that, anyone with a newer version can test if this behaviour is still present.
Delphi XE 10.3.3 behaves in the same way.

(To me, the behaviour feels like a bug.)
To me, too.

 

TinyPortal © 2005-2018