Page 1 of 1

problem with the size of PNG wxBitmap in wxToolBar

Posted: Thu Aug 17, 2006 9:17 am
by rayh
Dear all,

I'm having this problem when I tried to put PNG wxBitmap in a wxToolBar.
The size of the bitmap is not complete on the tool button!
Please advise me what to you~

Here is the result of the execution:

And the source code is as follows :

toolbar = new wxToolBar(this, wxID_ANY , wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL );

wxImage::AddHandler(new wxPNGHandler());

wxBitmap bmp1(wxT("../_bitmaps/GlobalIcons/FileIcon_01.png"), wxBITMAP_TYPE_PNG);
wxBitmap bmp2(wxT("../_bitmaps/GlobalIcons/FileIcon_02.png"), wxBITMAP_TYPE_PNG);

toolbar->AddTool(ID_NEW, bmp1, wxT("New file"));
toolbar->AddTool(ID_OPEN, bmp2, wxT("Open file"));


Posted: Thu Aug 17, 2006 2:27 pm
by benedicte
Did you try to "modify" a wxWidgets sample (such as "toolbar") so as to use your images, and see how it behaves?

Posted: Fri Aug 18, 2006 1:46 am
by rayh
Sorry, I'm not sure I know what you mean
Could you be more specific please?
I just started to use wxWidgets for 2 weeks, still a newbie...

Posted: Sat Aug 19, 2006 5:54 am
by benedicte
In your wxWidgets directory, there is a directory called "samples". There are many samples you can build and play with.
One of them is about toolbars. You can look this sample source code to see how it works, and if your code doesn't run properly, you can try to modify the sample source to use your images, build it and see if it works or not. If it doesn't work, you may conclude there is something wrong with the code you modified, and find the solution.

Posted: Sat Aug 19, 2006 11:04 pm
by cpp
Hi! I had that problem once, try calling wxToolBar::SetToolBitmapSize() to specify the size of your images, before adding the buttons. make shure you pass the correct size of your images.

Code: Select all

// create the toolbar
toolbar = new wxToolBar(this, wxID_ANY , wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL ); 

// set button image size (assuming the size is 16x16)

Posted: Mon Aug 21, 2006 2:21 am
by rayh
Wow! It works!
Thanks, you guys~
Coding in wxWidgets is so much fun~ :D