Create a Link with a Hover effect with fadeout effect

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
In need of some credit
In need of some credit
Posts: 1
Joined: Mon May 15, 2023 9:17 pm

Create a Link with a Hover effect with fadeout effect

Post by artyfunk »


Iam a Greenhorn in C++ and wxWidgets. I started to learn C++ and wxWIdgets.

I trying now to Create a Link as Menu.
With this Link i want to Switch for Exampe TExt in a TExtfeld on or Off.

The Link should have an Orange hover effect (when mouse over the link).
And when the Mouse leaves the Link it should fade slowly out for example 2 seconds or less.

i have no idea how to code this. i treid many times but don't get it to work.

Can someone help me out? Just a Sample?

I got here an code working but only with button instead of links.
#include <wx/wx.h>

class MyFrame : public wxFrame {
MyFrame(const wxString& title)
: wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxSize(400, 300)) {
m_textCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
auto vbox = new wxBoxSizer(wxVERTICAL);
vbox->Add(m_textCtrl, 1, wxEXPAND | wxALL, 10);
auto hbox = new wxBoxSizer(wxHORIZONTAL);
auto schalteANButton = new wxButton(this, wxID_ANY, "SchalteAN");
hbox->Add(schalteANButton, 0, wxALL, 10);
auto schalteAusButton = new wxButton(this, wxID_ANY, "SchalteAus");
hbox->Add(schalteAusButton, 0, wxALL, 10);
vbox->Add(hbox, 0, wxEXPAND);

schalteANButton->Bind(wxEVT_BUTTON, &MyFrame::OnSchalteANButtonClicked, this);
schalteAusButton->Bind(wxEVT_BUTTON, &MyFrame::OnSchalteAusButtonClicked, this);

void OnSchalteANButtonClicked(wxCommandEvent& event) {

void OnSchalteAusButtonClicked(wxCommandEvent& event) {

wxTextCtrl* m_textCtrl;

class MyApp : public wxApp {
bool OnInit() override {
auto frame = new MyFrame("Hello wxWidgets");
return true;

User avatar
[email protected]
Super wx Problem Solver
Super wx Problem Solver
Posts: 330
Joined: Wed Jul 29, 2020 6:06 pm

Re: Create a Link with a Hover effect with fadeout effect

Post by [email protected] »

For a control that mimics a link, use wxHyperlinkCtrl ... _ctrl.html

However, AFAIR the native implementation does not support changing its colors. If this is still the case you can use wxGenericHyperLinkCtrl instead ( include <wx/generic/hyperlink.h> ).

For the hover effect, catch the wxEVT_ENTER_WINDOW / wxEVT_LEAVE_WINDOW events ... event.html

In their event handlers, you can use a wxTimer to change the color over time.
Part Of The Furniture
Part Of The Furniture
Posts: 6904
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Create a Link with a Hover effect with fadeout effect


It is really BAD idea to learn C++ with wxWidgets or vice-versa.
Start with the language - go to local college, apply and learn the tool. Make sure you are comfortable with it.
Then come here and start playing with the library.

Thank you.
Post Reply