Label on bitmapButton

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
Qasim
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 23, 2007 3:41 pm
Location: London

Label on bitmapButton

Post by Qasim » Mon Apr 07, 2008 10:38 pm

Hi. Is it possible to have a label on bitmap button as well as bitmap. I am trying but only getting bitmap and no label. I am doing some thing like this...

Code: Select all

wxBitmap* bmpButton = new wxBitmapButton(myframe, -1, buttonBMP, wxPoint(-1,-1), wxSize(-1,-1), wxBU_RIGHT);
bmpButton->SetLabel("MyButton");
Any help will be appreciated.
Who doubts nothing, Knows nothing

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Tue Apr 08, 2008 2:38 am

Hi,

First, I think you have a typo in your example, it should be wxBitmapButton *bmpButton instead of wxBitMap.

If you want to overlay the label on the bitmap, you can use wxMemoryDC as follows:

Code: Select all


	wxMemoryDC memDC(buttonBMP);
	if (memDC.IsOk()) {
		memDC.DrawText(wxT("MyButton"),0,0);
	}

        wxBitmapButton* bmpButton = new wxBitmapButton(myframe, -1, buttonBMP, wxPoint(-1,-1), wxSize(-1,-1), wxBU_RIGHT);
Check
http://docs.wxwidgets.org/2.6.3/wx_wxmemorydc.html and
http://docs.wxwidgets.org/2.6/wx_wxdc.html
for more info.

Jim
OS: Vista SP1, wxWidgets 2.8.7.

Qasim
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 23, 2007 3:41 pm
Location: London

Post by Qasim » Tue Apr 08, 2008 8:32 am

sorry that was tying mistake. I wanted to clear the point that if wxBitmapButton was derived from wxButton, then why we cant set label to button, as well as bitmap (reather than drawing to it)
Who doubts nothing, Knows nothing

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Thu Apr 10, 2008 1:08 am

Hi,

The way it's set up makes sense to me (I didn't write the code).

I think of it as they are both buttons with the same or similar behavior (enable, clicking, etc.) and one has a text label and the other has a bitmap on it.

The fact that one derives from the other is matter of convenience and maintainability for the developers.

Rather than a label on a bitmap, what about a bitmap button with a tool tip to provide the guidance text?

Jim
OS: Vista SP1, wxWidgets 2.8.7.

Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

Post by Lloyd » Thu Apr 10, 2008 7:46 am

A bitmap button cant have a label. In that case you can prepare the bitmap with the particular label, and if you want to change the label during run time, change the bitmap.

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Thu Apr 10, 2008 10:25 am

Agreed, hence my first post.
OS: Vista SP1, wxWidgets 2.8.7.

Post Reply