wxBitmapButton change image Topic is solved
wxBitmapButton change image
Hi everybody.
There is an option to change images using wxBtmapButton :: SetBitmapSelected ()
When attempting to set wxBtmapButton :: SetBitmapSelected (), it is only possible at the beginning
and subsequent Refresh () does not change the picture
Thanks for the reaction
Win8.1
wxDev-C++ 7.4.2.569
There is an option to change images using wxBtmapButton :: SetBitmapSelected ()
When attempting to set wxBtmapButton :: SetBitmapSelected (), it is only possible at the beginning
and subsequent Refresh () does not change the picture
Thanks for the reaction
Win8.1
wxDev-C++ 7.4.2.569
Re: wxBitmapButton change image
I would try the "trick" which uses an invalid bitmap to "reset" the image.
viewtopic.php?f=1&t=44031
viewtopic.php?f=1&t=44031
Re: wxBitmapButton change image
not working
[img] [/img]
[img] [/img]
Re: wxBitmapButton change image
Hi,
Can you post relevant code?
Also, I presume you did verify that the bitmap is OK?
Thank you.
Can you post relevant code?
Also, I presume you did verify that the bitmap is OK?
Thank you.
Re: wxBitmapButton change image
It does work
Unfortunately the OP did not provide the wxWidgets version he uses, guessing from the obsolete IDE, perhaps he is also using an obsolete wxWidgets version (pre 3.x) which may behave differently. AFAIK, the button code was revamped around 2.9...
Code: Select all
#include <wx/wx.h>
#include <wx/bmpbuttn.h>
#include <wx/artprov.h>
class MyDlg : public wxDialog
{
public:
MyDlg() : wxDialog(NULL, wxID_ANY, "Test", wxDefaultPosition, wxSize(200, 200))
{
m_button = new wxBitmapButton(this, wxID_ANY, wxArtProvider::GetBitmap(wxART_PLUS , wxART_BUTTON));
m_switched = false;
UpdateButton();
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MyDlg::OnButtonClicked, this);
}
private:
wxBitmapButton* m_button;
bool m_switched;
void UpdateButton()
{
// reset the bitmap
m_button->SetBitmap(wxBitmap());
if ( m_switched )
m_button->SetBitmapPressed(wxArtProvider::GetBitmap(wxART_PLUS , wxART_BUTTON));
else
m_button->SetBitmapPressed(wxArtProvider::GetBitmap(wxART_MINUS, wxART_BUTTON));
}
void OnButtonClicked(wxCommandEvent&)
{
m_switched = !m_switched;
UpdateButton();
}
};
class MyApp : public wxApp
{
public:
bool OnInit()
{
MyDlg dlg;
dlg.ShowModal();
return false;
}
}; wxIMPLEMENT_APP(MyApp);
Re: wxBitmapButton change image
At startup
when changing
and there arises the problem with change
bitmap are ok
Code: Select all
mstarte0.LoadFile(wxT("Files\\start20.png"), wxBITMAP_TYPE_PNG);
mstarte1.LoadFile(wxT("Files\\start21.png"), wxBITMAP_TYPE_PNG);
mstarts0.LoadFile(wxT("Files\\starts0.png"), wxBITMAP_TYPE_PNG);
mstarts1.LoadFile(wxT("Files\\starts1.png"), wxBITMAP_TYPE_PNG);
mcale0.LoadFile(wxT("Files\\calc0.png"), wxBITMAP_TYPE_PNG);
mcale1.LoadFile(wxT("Files\\calc1.png"), wxBITMAP_TYPE_PNG);
mcals0.LoadFile(wxT("Files\\poc0.png"), wxBITMAP_TYPE_PNG);
mcals1.LoadFile(wxT("Files\\poc1.png"), wxBITMAP_TYPE_PNG);
mstop0.LoadFile(wxT("Files\\stop20.png"), wxBITMAP_TYPE_PNG);
mstop1.LoadFile(wxT("Files\\stop21.png"), wxBITMAP_TYPE_PNG);
Start->SetBitmapDisabled(mstarte0);
Start->SetBitmapSelected(mstarte1);
Stop->SetBitmapDisabled(mstop0);
Stop->SetBitmapSelected(mstop1);
Calculate->SetBitmapDisabled(mcale0);
Calculate->SetBitmapSelected(mcale1);
and there arises the problem with change
Code: Select all
Start->SetBitmapDisabled(wxBitmap());
Start->SetBitmapDisabled(mstarts0);
Start->SetBitmapSelected(wxBitmap());
Start->SetBitmapSelected(mstarts1);
Re: wxBitmapButton change image
Code: Select all
Start->SetBitmapDisabled(mstarts0);
Code: Select all
Start->SetBitmapSelected(mstarts1);
Use the source, Luke!
Re: wxBitmapButton change image
Yes, once I want to change it, there is a problem
Re: wxBitmapButton change image
Code: Select all
Start->SetBitmapDisabled(mstarts0);
Code: Select all
Start->Disable();
Please show the complete code that you use to change the button bitmap.
Use the source, Luke!
Re: wxBitmapButton change image
Code: Select all
Start->Disable();
Start->SetBitmapDisabled(mstarts0);
Start->SetBitmapSelected(mstarts1);
Start->Enable();
Re: wxBitmapButton change image
As I have found, Disable () has no influence on it
So only Start-> SetBitmapSelected (mstarts1) changes;
The problem arises when I use Start-> SetBitmapDisabled (wxNullBitmap);
So only Start-> SetBitmapSelected (mstarts1) changes;
Code: Select all
void AdcFrm::AdcFrmMouseEvents(wxMouseEvent& event)
{
int x, y, z;
char c;
long w;
float v, u;
wxString nam;
wxString moj;
wxString moj1;
bool cislo = false;
bool pl = false;
double akum;
wxFile file1;
if(event.Button(wxMOUSE_BTN_LEFT)){
event.GetPosition(&x, &y);
if(event.LeftDown()){
if(pozice == 7){
//Refresh();
//Update();
Mnuimport1044Click();
return;
}
if(pozice == 8){
//Refresh();
//Update();
Mnuexport1045Click();
return;
}
if(pozice == 9){
//Refresh();
//Update();
Mnuabout1046Click();
return;
}
if(pozice == 6){
//Refresh();
//Update();
Mnuadcdac1050Click();
return;
}
if(pozice == 5){
//Refresh();
//Update();
Mnuexit1041Click();
return;
}
if(pozice == 4){
//Refresh();
//Update();
Mnusaveas1040Click();
return;
}
if(pozice == 3){
//Refresh();
//Update();
Mnusave1039Click();
return;
}
if(pozice == 2){
//Refresh();
//Update();
dole = true;
//event.m_x = 400;
AdcFrmMouseMotion(event);
Mnuopen1038Click();
return;
}
if(pozice == 1){
//Refresh();
//Update();
dole = true;
//event.m_x = 400;
AdcFrmMouseMotion(event);
Mnunew1037Click();
return;
}
if(pozice == 10){
Start->Disable();
//Start->SetBitmapDisabled(wxNullBitmap);
//Start->SetBitmapSelected(wxNullBitmap);
Start->SetBitmapDisabled(mstarts0);
Start->SetBitmapSelected(mstarts1);
Start->Enable();
//Start->Refresh();
slo = 1;
Jazyk();
Refresh();
Update();
return;
}
if(pozice == 11){
slo = 0;
Jazyk();
Refresh();
Update();
return;
}
if(pozice == 12){
//Refresh();
//Update();
SetStandard();
return;
}
if(!menu){
if(x > meas.x && x < (meas.x+meas.width) && y > meas.y && y < (meas.y+meas.height)){
if(!measure){
Tabulka->Show(false);
TabFin->Show(false);
Kalibracia->Show(false);
Uhol45->Show(true);
Uhol90->Show(true);
Uhol135->Show(true);
Centrala->Show(true);
Start->Show(true);
Stop->Show(true);
Settings->Show(true);
WxStaticText4->Show(true);
WxStaticText5->Show(true);
WxStaticText6->Show(true);
Sample->Show(true);
Duration->Show(true);
Percenta->Show(true);
Conect->Show(true);
Conection->Show(true);
Calculate->Show(true);
measure = true;
Refresh();
Update();
}
}
if(x > cali.x && x < (cali.x+cali.width) && y > cali.y && y < (cali.y+cali.height)){
if(measure){
Uhol45->Show(false);
Uhol90->Show(false);
Uhol135->Show(false);
Centrala->Show(false);
Start->Show(false);
Stop->Show(false);
Settings->Show(false);
WxStaticText4->Show(false);
WxStaticText5->Show(false);
WxStaticText6->Show(false);
Sample->Show(false);
Duration->Show(false);
Percenta->Show(false);
Conect->Show(false);
Conection->Show(false);
Calculate->Show(false);
Kalibracia->Show(true);
Tabulka->Show(true);
TabFin->Show(true);
measure = false;
Refresh();
Update();
}
}
}
}
}
event.Skip();
}
Re: wxBitmapButton change image
Solved
Thank you for your reactions
Code: Select all
Start->SetBitmapLabel(mstarts0);
Start->SetBitmapSelected(mstarts1);
Re: wxBitmapButton change image
Code: Select all
Start->Disable();
Start->SetBitmapDisabled(mstarts0);
Start->SetBitmapSelected(mstarts1);
Start->Enable();
Use the source, Luke!
Re: wxBitmapButton change image
doublemax,
The OP probably misunderstands the different states the control can be in.
Thank you.
The OP probably misunderstands the different states the control can be in.
Thank you.