[wxDesigner] Using Designer to subclass my GUI objects other
than dialogs
Robert Roebling
robert at roebling.de
Mon Jul 2 13:03:49 PDT 2007
David Goldsmith wrote:
> Now for my present question. I'm porting a native libraries code to
> wxWidgets using wxDesigner to reproduce the GUI. One of the features of
> the old code is that the menu bar changes in response to the user
> selecting certain menu bar items, but it changes only a little, most of
> it stays the same. Leveraging wxDesigner, my first plan of attack was
> to compose the main menu bar, then simply copy the whole thing and paste
> it into a new menu bar object and add the additional material and then
> swap out menu bars as appropriate in the main wxFrame. However, I
> realized the more OO thing to do would be to subclass the main menu bar,
> adding additional members as needed (and still swapping out exactly
> which class is being used for the menu at any given time in the app, of
> course).
You are the first to ask to subclass wxMenubar and I'd say this
is never needed and doesn't make sense. You can modify a menubar
inplace by getting the wxMenuItems by ID. You can then add,
change and remove menu items as you like. As much as I like OO,
it doesn't make sense for every problem.
> I see that wxDesigner has a class-writing function for dialog objects,
> but I don't see that functionality for any other objects. Also, I
> examined the code that Designer actually produces, and it does not
> appear to be creating a class to encapsulate even my main menu bar. Is
> there a way to leverage Designer to help me perform the subclassing I
> have described?
No, wxDesigner doesn't provide a way to subclass wxMenubar. I'd
probably create a single menubar with wxDesiger and instantiate
it twice (or more times) in your app, modifiying it as you need.
You can then swap out menubars as you described.
Robert
More information about the wx-users
mailing list