Page 1 of 1
wxBitmapButton change image
Posted: Fri Mar 23, 2018 12:53 pm
by palikem
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
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 1:42 pm
by PB
I would try the "trick" which uses an invalid bitmap to "reset" the image.
viewtopic.php?f=1&t=44031
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 2:03 pm
by palikem
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 3:02 pm
by ONEEYEMAN
Hi,
Can you post relevant code?
Also, I presume you did verify that the bitmap is OK?
Thank you.
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 3:21 pm
by PB
It does work
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);
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...
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 3:22 pm
by palikem
At startup
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);
when changing
and there arises the problem with change
Code: Select all
Start->SetBitmapDisabled(wxBitmap());
Start->SetBitmapDisabled(mstarts0);
Start->SetBitmapSelected(wxBitmap());
Start->SetBitmapSelected(mstarts1);
bitmap are ok
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 4:09 pm
by doublemax
Code: Select all
Start->SetBitmapDisabled(mstarts0);
This bitmap would only be visible if the button is disabled. Is it?
Code: Select all
Start->SetBitmapSelected(mstarts1);
This bitmap would only be visible if the button is selected. Is it?
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 4:24 pm
by palikem
Yes, once I want to change it, there is a problem
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 4:27 pm
by doublemax
Code: Select all
Start->SetBitmapDisabled(mstarts0);
This bitmap will only be visible if the button is in "disabled" state. Which means you'd have to call.
somewhere. Do you do that?
Please show the complete code that you use to change the button bitmap.
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 4:47 pm
by palikem
Code: Select all
Start->Disable();
Start->SetBitmapDisabled(mstarts0);
Start->SetBitmapSelected(mstarts1);
Start->Enable();
Disable () helped, but only changed the image in Start-> SetBitmapSelected (mstarts1);
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 5:06 pm
by palikem
As I have found, Disable () has no influence on it
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();
}
The problem arises when I use Start-> SetBitmapDisabled (wxNullBitmap);
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 5:13 pm
by palikem
Solved
Code: Select all
Start->SetBitmapLabel(mstarts0);
Start->SetBitmapSelected(mstarts1);
Thank you for your reactions
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 5:15 pm
by doublemax
Code: Select all
Start->Disable();
Start->SetBitmapDisabled(mstarts0);
Start->SetBitmapSelected(mstarts1);
Start->Enable();
That's not what i meant. The "disabled" bitmap is displayed when the button is in "disabled" state. Like when a normal control is "greyed out", indicating that you can't use it.
Re: wxBitmapButton change image
Posted: Fri Mar 23, 2018 5:56 pm
by ONEEYEMAN
doublemax,
The OP probably misunderstands the different states the control can be in.
Thank you.