problem with the size of PNG wxBitmap in wxToolBar Topic is solved

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
rayh
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Aug 17, 2006 9:04 am

problem with the size of PNG wxBitmap in wxToolBar

Post 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:
Image

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"));

toolbar->Realize();
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Did you try to "modify" a wxWidgets sample (such as "toolbar") so as to use your images, and see how it behaves?
rayh
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Aug 17, 2006 9:04 am

Post 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...
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post 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.
cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Post 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.
eg.

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)
toolbar->SetToolBitmapSize(wxSize(16,16));
HTH
Hier Kommt die Sonne...
rayh
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Aug 17, 2006 9:04 am

Post by rayh »

Wow! It works!
Thanks, you guys~
Coding in wxWidgets is so much fun~ :D
Post Reply