Search code examples
rubywxruby

StaticText / StaticBitmap on Button blocking events


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?


Solution

  • 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.