Discussion:
Context menu for button
Tim Burgess
2014-07-16 09:22:38 UTC
Permalink
Hi,

My port of a QT application to WX continues - I've successfully got a
wxGridSizer laying out my 100 buttons - I now have to provide a context
menufor each button (I agree that this is a nonsense, but I'm still trying
to keep as close to the original application as I can). I've coded the
context menu so that it successfully brings up the options that I want, but
I'm confused as to how I can reliably grab the ID of the button that had
focus before the menu appeared so that I can pass it along for further
processing, since the button doesn't support a right-click event and I'm
having to use EVT_CONTEXT_MENU. Querying the context menu event will return
the ID of the chosen menu option, obviously, and so will a call based on
getting the focus - I'm a bit stuck, so can anybody offer any suggestions,
please?

Best wishes.
Tim Burgess
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Eran Ifrah
2014-07-16 09:34:25 UTC
Permalink
IIUC, you are trying to use a single event handler (e.g. OnButtonMenu) for
all of 100 buttons?
If this is the case, you could try using:

wxButton* button = dynamic_cast<wxButton*>(event.GetEventObject());

which should return the button that triggered the context menu event

Eran
Post by Tim Burgess
Hi,
My port of a QT application to WX continues - I've successfully got a
wxGridSizer laying out my 100 buttons - I now have to provide a context
menufor each button (I agree that this is a nonsense, but I'm still trying
to keep as close to the original application as I can). I've coded the
context menu so that it successfully brings up the options that I want, but
I'm confused as to how I can reliably grab the ID of the button that had
focus before the menu appeared so that I can pass it along for further
processing, since the button doesn't support a right-click event and I'm
having to use EVT_CONTEXT_MENU. Querying the context menu event will return
the ID of the chosen menu option, obviously, and so will a call based on
getting the focus - I'm a bit stuck, so can anybody offer any suggestions,
please?
Best wishes.
Tim Burgess
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
or visit http://groups.google.com/group/wx-users
--
Eran Ifrah
Author of codelite, a cross platform open source C/C++ IDE:
http://www.codelite.org
wxCrafter, a wxWidgets RAD: http://wxcrafter.codelite.org
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Tim Burgess
2014-07-16 12:36:15 UTC
Permalink
Great stuff – many thanks.





Best wishes.

Tim Burgess



From: wx-***@googlegroups.com [mailto:wx-***@googlegroups.com] On Behalf Of Eran Ifrah
Sent: 16 July 2014 10:34
To: wx-***@googlegroups.com
Subject: Re: Context menu for button



IIUC, you are trying to use a single event handler (e.g. OnButtonMenu) for all of 100 buttons?

If this is the case, you could try using:



wxButton* button = dynamic_cast<wxButton*>(event.GetEventObject());



which should return the button that triggered the context menu event



Eran





On Wed, Jul 16, 2014 at 12:22 PM, Tim Burgess <***@raisedbar.net> wrote:

Hi,

My port of a QT application to WX continues - I've successfully got a
wxGridSizer laying out my 100 buttons - I now have to provide a context
menufor each button (I agree that this is a nonsense, but I'm still trying
to keep as close to the original application as I can). I've coded the
context menu so that it successfully brings up the options that I want, but
I'm confused as to how I can reliably grab the ID of the button that had
focus before the menu appeared so that I can pass it along for further
processing, since the button doesn't support a right-click event and I'm
having to use EVT_CONTEXT_MENU. Querying the context menu event will return
the ID of the chosen menu option, obviously, and so will a call based on
getting the focus - I'm a bit stuck, so can anybody offer any suggestions,
please?

Best wishes.
Tim Burgess


--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com <mailto:wx-users%***@googlegroups.com>
or visit http://groups.google.com/group/wx-users
--
Eran Ifrah
Author of codelite, a cross platform open source C/C++ IDE: http://www.codelite.org

wxCrafter, a wxWidgets RAD: http://wxcrafter.codelite.org
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...