Is there any way to add a hint or tooltip with Fir

2020-06-18 04:05发布

I've earched for it but couldn't find anything. Is there any way to add a hint or tooltip with FireMonkey? Are there any components available that enable this?

Ideally I am looking for something like this (a callout type tooltip):

a callout type tooltip

To the moderators who have placed this question on hold: I am looking for lines of source code on how to achieve this, not a software to buy/use. There are currently (AFAIK) no source code components that enable doing this, so there is no risk of "opinionated anwers or spam".

4条回答
你好瞎i
2楼-- · 2020-06-18 04:32

I am new to Delphi and FireMonkey. And I also wanted tool tips. And here is what I figured out: FireMonkey has no provision for tool tips, and this is deliberate and for good reason.

I think the big idea with FireMonkey is that you develop one and only one program. Then, without changing even one line of code, you compile a version to run on Windows, another version to run on Android, another version to run on Mac OS, etc. So without changing even one line of code, you have a version for Desktop and a version for Smartphones that work exactly the same way with the same user interface.

Therefore, FireMonkey is only going to support features that are common to both smartphones and desktops. On smartphones, there is no such thing as hovering a mouse, a finger, or anything else. Therefore, Firemonkey does not support hovering on desktops. Because there is no hovering, there can be no tooltips ('hints' in Delphi nomenclature).

So you have to decide: Do you want an app that works exactly the same in Windows and on smartphones, without changing the code and without having separate code? Or do you want all the desktop features? If you want all the desktop features, including tooltips (hints) and all the rest, then you should be using Embarcadero's VCL (Visual Component Library). Using VCL will allow you to get tooltips (hints) by just setting the 'hint' property of text boxes, buttons, and all the other controls--and without writing code.

But if you want an app that works on smartphones, you will have to use FireMonkey. VCL won't work for that.

As I mentioned, I'm still new to Delphi. So, of course, I appreciate corrections from experienced Delphi developers.

查看更多
淡お忘
3楼-- · 2020-06-18 04:33

This is how I finally did it: to create a hint for a Button that looks like this:

enter image description here

Add a button to a form. Then add a TPopup. Drop a CalloutPanel inside it and optionally set the align to AlClient. The drop a TLabel on that CalloutPanel and write your hint text.

Your structure should look like this:

enter image description here

Then go to the TPopup and set PlacementTarget to Button1 (your button). Next, go to Placement and select BottomCenter:

enter image description here

Next add a handler for the MouseEnter and MouseLeave events on the button:

procedure TForm1.Button1MouseEnter(Sender: TObject);
begin
Popup1.IsOpen := True;
end;

procedure TForm1.Button1MouseLeave(Sender: TObject);
begin
Popup1.IsOpen := False;
end;

That should do it.

查看更多
别忘想泡老子
4楼-- · 2020-06-18 04:42

this "should do it" is a very nice workaround but if you mouse is inside the callout panel it flickers like mad - any thought on how to avoid it ?

I wish firemonkey was not always in a state of half-way done the android word has notifications but not in windows

查看更多
做个烂人
5楼-- · 2020-06-18 04:44

You can use FloatAnimation and Opacity property to make a hint.

Add a button to a form. Then add CalloutPanel (or any shape) inside. Next drop a TLabel on the CalloutPanel to write your hint text. I set CalloutPanel.Visible property to False at the Form Creating moment. Then attach a TFloatAnimation to a CalloutPanel.Opacity property.

Next set some TFloatAnimation properties:

Because of Duration Hint appears smoothly.

Then create Button events OnMouseEnter and OnMouseLeave .

procedure TForm1.Button1MouseEnter(Sender: TObject);
begin
   CalloutPanel1.Visible := true;
end;

procedure TForm1.Button1MouseLeave(Sender: TObject);
begin
   CalloutPanel1.Visible := false;
end;

That's it

查看更多
登录 后发表回答