Problem setting Image1 (wxImage) to wxBitmapButton [wxWidgets 3.1.3]

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
var_null
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu Feb 27, 2020 6:44 pm

Problem setting Image1 (wxImage) to wxBitmapButton [wxWidgets 3.1.3]

Post by var_null » Sat Mar 21, 2020 4:58 am

Hello,

Added a wxImage (called Image1) element with wxSmith, the original png image was converted to code, which is very long so I'm ommiting it

Have the following code:

Code: Select all

Project__Frame::Project__Frame(wxWindow* parent,wxWindowID id)
{

...

    static const char *Image1_XPM[] = { 
    ...
    };
    Image1 = new wxImage(Image1_XPM);
    Image1_BMP = new wxBitmap(Image1_XPM);
    
...
}

...

void Project__Frame::On_BitmapButton_Project_Click(wxCommandEvent& event)
{
    bitmapbutton_Project->SetBitmap(wxBitmap(wxImage(Image1)));
}
I get the following error (regarding the "bitmapbutton_Project->SetBitmap(wxBitmap(wxImage(Image1)));" line):

Code: Select all

error: no matching conversion for functional-style cast from 'wxImage *' to 'wxImage'
What would the correct code look like?

Thanks!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2386
Joined: Sun Jan 03, 2010 5:45 pm

Re: Problem setting Image1 (wxImage) to wxBitmapButton [wxWidgets 3.1.3]

Post by PB » Sat Mar 21, 2020 7:57 am

You seem to be passing a pointer to wxImage where a refernce to wxImage is expected.

The code should probably look like this (still quite ugly)

Code: Select all

bitmapbutton_Project->SetBitmap(wxBitmap(*Image1));
or

Code: Select all

bitmapbutton_Project->SetBitmap(*Image1_BMP);

var_null
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu Feb 27, 2020 6:44 pm

Re: Problem setting Image1 (wxImage) to wxBitmapButton [wxWidgets 3.1.3]

Post by var_null » Sat Mar 21, 2020 8:18 am

Thanks, that worked great

Post Reply