Mouse Event question Topic is solved

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
Clutch
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Apr 21, 2009 6:38 am

Mouse Event question

Post by Clutch »

Im fairly new to programming and wxWidgets, but I understand most of the concepts and do have some programming experience. My question is, I want to use a motion mouse event when the mouse rolls over a button to change some static text(wxStaticText). Any advice on how I would accomplish this? I assume an event table but what is the syntax for setting up something like that?

Thanks
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum »

Hi Clutch

I would take a look to the wxMouseEvent, in particular

EVT_ENTER_WINDOW(func)
EVT_LEAVE_WINDOW(func)

greetings
spectrum
Clutch
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Apr 21, 2009 6:38 am

Post by Clutch »

Perhaps you could guide me a little more. So say I were to set up something similar to this:

Code: Select all


BEGIN_EVENT_TABLE(myClass, wxFrame)

EVT_ENTER_WINDOW(myClass::myFunction)

END_EVENT_TABLE()

This is what confuses me, theres no ID in the parameters so how do I direct the event?

Or am I supposed to implement another event table in my function that I go to from an EVT_BUTTON in the global scope event table.

Hope this clarifies my question a little. Thanks
Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver »

You need to create a new object that inherits from your button (for example, you want the mouse to display a text when the mouse is over the button).
So you create a myButton that is derived from wxButton.

Into this class, you put your event table like:

Code: Select all

BEGIN_EVENT_TABLE(myButton, wxButton)

EVT_ENTER_WINDOW(myButton::myFunctionButton)

END_EVENT_TABLE() 
And into this function you can access the GetParent() element (that is your frame) in order to write into your static text your text, as GetParent()->myStaticText->SetLabel(...).

Now, in your frame, instead of creating a new wxButton, you create a "myButton" object.

Good luck.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Or alternatively, if you don't want to derive, you can use ->Connect(...) instead of event tables, which allow redirecting events
Clutch
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Apr 21, 2009 6:38 am

Post by Clutch »

Could you explain the Connect function just a little bit more? My google searches are turning up dry lol. Thanks

Edit:

I found this http://wiki.wxwidgets.org/Example_Of_Us ... For_Events

I understand everything except for the connect part, could anyone explain it? Thank you

Edit: Also for some reason this wont compile.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Clutch
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Apr 21, 2009 6:38 am

Post by Clutch »

Thank you very much! that blog basically solved everything lol.
Post Reply