1

So I have a simple setup here where I make a button, place a bitmap and some text on it, and then hook up an event handler.

@scanButton = Wx::Button.new(self, -1, '', @@SCAN_BUTTON_POS, :size => @@SCAN_BUTTON_SIZE)
@scanBitmap = Wx::StaticBitmap.new(@scanButton, -1, bitmap, @@SCAN_BITMAP_POS)
@scanHint = Wx::StaticText.new(@scanButton, -1, 'Scan', @@SCAN_HINT_POS, :style => Wx::ALIGN_CENTER)

You would think the default behavior here would be that a click anywhere on the button, even if it were over the text or the bitmap (as they are static / non-focusable) would be to forward the event up to the parent (button) and the button would be clicked.

Instead, clicking on the button outside the bounds of the static text / static bitmap is the only way to click the button. Clicking on the bitmap or text has no effect. I have tried forwarding events from the bitmap / text up to the parent, but that also fails to work. Does anyone have any suggestions? Perhaps there is some default behavior of wxWidgets I don't know about?

James
  • 5,355
  • 2
  • 18
  • 30

2 Answers2

1

Why aren't you using a Wx::BitmapButton? http://wxruby.rubyforge.org/doc/bitmapbutton.html

For the "hint" i would use a Wx::ToolTip associated with the @scanButton http://wxruby.rubyforge.org/doc/tooltip.html

Lucas d. Prim
  • 787
  • 1
  • 5
  • 17
  • The bitmap needs to be left-aligned and the text placed near it. The Wx::BitmapButton has a left-align option, but this only works on Windows (according to the docs), and I need to remain platform agnostic. I have tried using a ToolTip as well, but it fails to work in this case because I am making a 'stay on top' window over Google Sketchup that won't always have focus, so the tooltip won't trigger. Somewhat of a special case I fear. – James Mar 29 '11 at 15:43
0

It looks as though there currently is no answer to this - the contained text elements will block mouse events. A somewhat hackish solution is to make a single bitmap button that contains a bitmap that has the required text embedded int the bitmap. This only works if the text is static and never changes.

James
  • 5,355
  • 2
  • 18
  • 30