Home > Back-end >  Having trouble setting background of an event with its ID | WxWidgets
Having trouble setting background of an event with its ID | WxWidgets

Time:05-29

I believe I've done something similar in wxPython where I've changed an event by grabbing the Id or object and setting the object's background from there. In WxWidgets I seem to be having trouble though, I keep on getting errors like operator -> or ->* applied to "int" instead of to a pointer type. I'd like to be able to get the event's parent's Id/object and the event's Id/object in order to change their background/properties. I also had no luck in finding anything that mentioned an event's parent in the documentation.

I've tried different using different methods like GetEventObject() and GetEventUserData() and making the EventId a pointer. I'm new to C so pointers are still new to me so I didn't expect anything to work. Any help is much appreciated.

Code:

void MyFrame::OnMenuTxtBtnLeftClick(wxMouseEvent& event) {
    int EventId = event.GetId();
    EventId->SetBackgroundColour(wxColour(217, 217, 217, 19));

CodePudding user response:

The problem is that EventId is an int and thus the operator -> cannot be used with it.

You can try out the following that uses GetEventOjbect:

wxObject *obj = event.GetEventObject();
((myPanel *) obj)->SetBackgroundColour(wxColour(217, 217, 217, 19)); 
//^^^^^^^----------------------------->use your own type here
  • Related