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
artyfunk
Experienced Solver
Experienced Solver
Posts: 82
Joined: Mon May 15, 2023 9:17 pm

Create a Link with a Hover effect with fadeout effect

Post by artyfunk »

hello,

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 {
public:
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);
hbox->AddStretchSpacer(1);
auto schalteAusButton = new wxButton(this, wxID_ANY, "SchalteAus");
hbox->Add(schalteAusButton, 0, wxALL, 10);
vbox->Add(hbox, 0, wxEXPAND);
SetSizerAndFit(vbox);

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

private:
void OnSchalteANButtonClicked(wxCommandEvent& event) {
m_textCtrl->SetValue("OK");
}

void OnSchalteAusButtonClicked(wxCommandEvent& event) {
m_textCtrl->Clear();
}

wxTextCtrl* m_textCtrl;
};

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

wxIMPLEMENT_APP(MyApp);
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

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

Post by doublemax@work »

For a control that mimics a link, use wxHyperlinkCtrl
https://docs.wxwidgets.org/trunk/classw ... _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
https://docs.wxwidgets.org/trunk/classw ... event.html

In their event handlers, you can use a wxTimer to change the color over time.
https://docs.wxwidgets.org/trunk/classwx_timer.html
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN »

Hi,
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