Hi,
I have a wxTextCtrl with multiple words separated by comma. I would like to change these words to hyperlinks and react when user clicks on them.
So far I have found out that if I change the style of wxTextCtrl to wxTE_AUTO_URL and wxTE_RICH and change my words to start with http:// (or ftp:// etc.. to be recognized as link) I get them as links and can react to the user clicking on them.. so far so good.
I would now like to know if its possible to hide the http:// from the shown text (basically to act like label for wxHyperlinkCtrl) or if there is some other way how to tell the wxTextCtrl that the words I am providing should be treated as hyperlinks without the need of adding http:// to the string.
I am guessing that it is going to be possible with right use of wxRichTextCtrl... but it would be so much easier if I could do it without it (we don't properly support wxRichTextCtrl atm.
Need custom label for hyperlink in wxTextCtrl
-
- Earned a small fee
- Posts: 14
- Joined: Thu Sep 03, 2020 9:10 am
Re: Need custom label for hyperlink in wxTextCtrl
I don't think it is possible with wxTextCtrl, at least not on Windows. The URI must be present for the hyperlink to work:
https://learn.microsoft.com/en-us/windo ... ct#remarks
https://learn.microsoft.com/en-us/windo ... ct#remarks
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: Need custom label for hyperlink in wxTextCtrl
With wxStyledTextCtrl, you can set a style to be a hot spot style. When text with that style, is clicked a wxEVT_STC_HOTSPOT_CLICK event will be generated.
-
- Earned a small fee
- Posts: 14
- Joined: Thu Sep 03, 2020 9:10 am
Re: Need custom label for hyperlink in wxTextCtrl
Well, if TextCtrl can't do it... :/
Thanks for suggestion of StyledTextCtrl - I will look into it (hopefully shortly)
I also just realized that it could also be possible to get what I want with just generating multiple wxHypelinkCtrl in a row... with wxWrapSizer it could be pretty identical to wxTextCtrl with multiple words.
Thanks for suggestion of StyledTextCtrl - I will look into it (hopefully shortly)
I also just realized that it could also be possible to get what I want with just generating multiple wxHypelinkCtrl in a row... with wxWrapSizer it could be pretty identical to wxTextCtrl with multiple words.
Re: Need custom label for hyperlink in wxTextCtrl
If the control is going to be read-only, did you try wxHTMLWindow?Nathaniell wrote: ↑Mon Oct 03, 2022 8:52 pm I also just realized that it could also be possible to get what I want with just generating multiple wxHypelinkCtrl in a row... with wxWrapSizer it could be pretty identical to wxTextCtrl with multiple words.
-
- Earned a small fee
- Posts: 14
- Joined: Thu Sep 03, 2020 9:10 am
Re: Need custom label for hyperlink in wxTextCtrl
In case someone stumbles on this in later google search...
In the end, I have styled the text with SetStyle (you need RICH flag) -> set the blue color and underline, and I am reacting on wxEVT_LEFT_UP (wxEVT_COMMAND_LEFT_CLICK didn't work). After the click, I extract the clicked position with HitTest and test that we clicked on the text, not on the empty space in the textCtrl with wxTE_HT_ON_TEXT... and from there, you just extract the word on that position and you are done (and can react to it).
In the end, I have styled the text with SetStyle (you need RICH flag) -> set the blue color and underline, and I am reacting on wxEVT_LEFT_UP (wxEVT_COMMAND_LEFT_CLICK didn't work). After the click, I extract the clicked position with HitTest and test that we clicked on the text, not on the empty space in the textCtrl with wxTE_HT_ON_TEXT... and from there, you just extract the word on that position and you are done (and can react to it).