Question about BitmapButton

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.
DaiyaO
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Dec 07, 2017 9:52 am

Question about BitmapButton

Post by DaiyaO »

Hello,

I just start learning wxWidget.I tried creating buttons with the same event handler and used this code to change the image of the buttons.

Code: Select all

EVT_BUTTON(4010, BoardWindow::Response)


void BoardWindow::Response(wxCommandEvent & event)
{
	wxBitmapButton *temp = (wxBitmapButton*)event.GetEventObject();
	temp->SetBitmap(*newimage);
}
It only works when i clicked the first created buttons and changed the image as i move my mouse to the other button.

Is there any fixes to this?

Many thanks and greetings
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7481
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Question about BitmapButton

Post by ONEEYEMAN »

Hi,
Which OS/toolkit?
Which wx version?

Do you mean you click the button then move the mouse to the next button and then the bitmap is changed? It is not changed immediately when the button is clicked?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about BitmapButton

Post by doublemax »

To make sure that the event object really is a wxBitmapbutton, use code like this:

Code: Select all

 wxBitmapButton *temp = wxDynamicCast( event.GetEventObject(), wxBitmapButton );
 if( temp )
 {  
  temp->SetBitmap(*newimage);
  temp->Refresh();
 }
Also, you may need to call Refresh() to make the new bitmap appear.

How do you connect the event to the other buttons? Do you have multiple entries in the event table? Or do you create all buttons with the same ID? The second version would be the wrong way to do it.
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Question about BitmapButton

Post by PB »

In addition to what has already been said, you may be running into an issue described here
viewtopic.php?f=1&t=44031