SetLabel() on wxBitmapButton does not work as expected

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
viveks485
Earned a small fee
Earned a small fee
Posts: 15
Joined: Tue Apr 19, 2016 7:35 am

SetLabel() on wxBitmapButton does not work as expected

Postby viveks485 » Tue May 30, 2017 8:22 am

Hi Team,

I am using wxWidgets 3.0.2 for my application which works on Windows and MAC. I have a problem in using SetLabel function for wxBitmapButton control. For supporting automation of my application, I need to set label to each and every control. For other controls it works fine but for wxBitmapButton when I set the label, it shows the label string on the button by overriding the bitmap which is not we are expecting. On Windows it work fine but on MAC I face this issue.
Since my bitmap buttons are actually using bitmaps which are proper images, any string overriding it looks bad. On Windows I am able to set the labels without getting it shown on the controls but on MAC I am having this issue. Please help me to resolve it or provide me other alternative (if any) to setlabels without showing it.

Following is the code where I am creating the button and setting the labels which is very simple :

wxBitmap bmp;

bmp = *( m_lptoolBarBitmaps[ BITMAPID_PREV ] );
wxBitmapButton *goPrevButton = new wxBitmapButton( bottomToolBackgroundPanel, ID_VEDIT_PREVSURFACE, bmp, wxDefaultPosition,
wxDefaultSize, wxBORDER_NONE );
goPrevButton->SetBackgroundColour(bottomToolBackgroundPanel->GetBackgroundColour());
goPrevButton->SetBitmapCurrent( bmp );
goPrevButton->SetBitmapDisabled( *( m_lptoolBarBitmaps[ BITMAPID_PREV + 1 ] ) );
goPrevButton->SetBitmapHover( *( m_lptoolBarBitmaps[ BITMAPID_PREV + 2 ] ) );
goPrevButton->SetBitmapPressed( *( m_lptoolBarBitmaps[ BITMAPID_PREV + 3 ] ) );
goPrevButton->SetLabel(_("Previous Page"));
bottomToolInternalSizer->Add( goPrevButton, 0, wxALIGN_CENTER );
bottomToolInternalSizer->AddSpacer( 5 );

PFA the screenshot of the application window where the bitmap buttons are shown getting overridden with the set labels in black rectangles.

Thanks,
Vivek
Attachments
error.png

Anil8753
Experienced Solver
Experienced Solver
Posts: 60
Joined: Sat Jan 16, 2016 5:57 am

Re: SetLabel() on wxBitmapButton does not work as expected

Postby Anil8753 » Wed Jul 12, 2017 10:06 am

try it

Code: Select all

   const wxBitmap bmpNormal = ...;
    const wxBitmap bmpSelected = ...;

    wxButton* pBtn = new wxButton(this, wxID_ANY, wxEmptyString,
        wxDefaultPosition, bmpNormal.GetSize(), wxTRANSPARENT_WINDOW | wxBORDER_NONE);

    pBtn->SetLabelText("YOUR LABEL");
    pBtn->SetBitmap(bmpNormal);
    pBtn->SetBitmapHover(bmpSelected);
    pBtn->SetBitmapPressed(bmpSelected);
    pBtn->SetBackgroundColour(GetBackgroundColour());

User avatar
xaviou
Super wx Problem Solver
Super wx Problem Solver
Posts: 376
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

Re: SetLabel() on wxBitmapButton does not work as expected

Postby xaviou » Thu Jul 13, 2017 6:04 am

Hi.

Did you try updating your sizers after changing the buttons labels ?

Code: Select all

......
goPrevButton->SetLabel(_("Previous Page"));
bottomToolInternalSizer->Add( goPrevButton, 0, wxALIGN_CENTER );
bottomToolInternalSizer->AddSpacer( 5 );
bottomToolInternalSizer->Layout();


Regards
Xav'
The french wxWidgets site : Image
My wxWidgets stuff web page : X@v's wxStuff


Return to “Platform Related Issues”

Who is online

Users browsing this forum: No registered users and 2 guests