Drawing button on a wxStaticBitmap 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
Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Drawing button on a wxStaticBitmap

Post by Muetdhiver » Tue Sep 27, 2011 3:35 pm

Hi,

I simply want to draw wxButton on a wxStaticBitmap that is the background image of a wxDialog.
I don't have sizer, I just want to do a simple dialog that show an image with one button on this image, something really simple.

I think a way to do that should be to use the OnPaint event and draw the background bitmap but is this possible with just a wxStaticBitmap ?

In my dialog constructor, I declare 3 buttons, located with x, y coordinates, something ugly but simple :

Code: Select all

wxButton* myButtonResultTab = new wxButton(this, wxID_RESULT_TAB, _S(TLang::Get("result_tab")), wxPoint(20,this->GetSize().y-50-15), wxSize(160,23));
	
etc.

Then I just declare a staticbitmap :

Code: Select all

(void*) new wxStaticBitmap(this, -1, wxBitmap( loc_o_background_image ), wxPoint(0,0));
that is my background.

The result is that the window show well the bitmap, but the buttons aren't drawn.
If I simply move the dialog out of the screen (with a manual user action by the mouse !) and then put it back, buttons appear because it forces the frame to be refreshed.
I tried to add a "Refresh()" call after the staticbitmap declaration, but nothing happen, i still need to move the window with my mouse for the button to be displayed.

There is a way to force the draw of the button or must I do something more complicated ?

Thanks a lot.
Bye.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

User avatar
doublemax
Moderator
Moderator
Posts: 15512
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing button on a wxStaticBitmap

Post by doublemax » Tue Sep 27, 2011 3:46 pm

The button must have the wxStaticBitmap as parent.
Use the source, Luke!

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Re: Drawing button on a wxStaticBitmap

Post by Muetdhiver » Wed Sep 28, 2011 7:03 am

Thanks a lot.
This works well.

That was not working only on Windows. On Ubuntu, even with "this" as parent, it works, but I think it is a GTK particurality. That why I thought I would be more difficult to solve.
Again thanks.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Re: Drawing button on a wxStaticBitmap

Post by Muetdhiver » Fri Oct 21, 2011 1:59 pm

Hi !!!


I've tested this solution, under MSW it works, but after a long time I decided to run it under Ubuntu, and an ASSERT is raised at runtime : impossible to add children of wxStaticBitmap....
So, I need to add this code for this to work under both environment :

Code: Select all

wxStaticBitmap* loc_po_background = new wxStaticBitmap(this, -1, wxBitmap( loc_o_background_image ), wxPoint(0,0));

	//Button 'Display result tab'
#ifdef __WXMSW__
	wxButton* myButtonResultTab = new wxButton(loc_po_background, wxID_RESULT_TAB, _S(TLang::Get("result_tab")), wxPoint(20,this->GetSize().y-50-15), wxSize(160,23));
#else
	wxButton* myButtonResultTab = new wxButton(this, wxID_RESULT_TAB, _S(TLang::Get("result_tab")), wxPoint(20,this->GetSize().y-50-15), wxSize(160,23));
#endif
Do you think this is normal ???
It is really sad (and thus, ugly) to make a different code under linux and windows system.... wxWidgets is not done for that.....
What do you think about this ?

Thanks
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Re: Drawing button on a wxStaticBitmap

Post by Muetdhiver » Thu Oct 27, 2011 9:39 am

Nobody for my previous question ?

Or may I do a new post ?

++
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Drawing button on a wxStaticBitmap

Post by Auria » Thu Oct 27, 2011 2:34 pm

Try to replace the static bitmap with this : wiki.wxwidgets.org/An_image_panel

This should work across all platforms (wxStaticBitmap is meant as a UI icon, not as a background, so adding things to it may not work everywhere)
"Keyboard not detected. Press F1 to continue"
-- Windows

Post Reply