cast subclassed widget

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
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

cast subclassed widget

Post by papillon68 »

Hello and sorry for the newbie question. I'm using the OpenGL/pyramid sample and I'd like to the glCanvas into a wxPanel rather than the main frame.
In the sample:

Code: Select all

if ( accepted ) 		m_mycanvas = new MyGLCanvas(this, vAttrs);
the canvas this parent is a subclassed wxFrame (MyFrame).

I'd like to go this way instead:

Code: Select all

wxPanel *oglPane = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(300, 200));
 if ( accepted ) 		m_mycanvas = new MyGLCanvas(oglPane, vAttrs);
Now, I've searched and tried using wxDynamicCast but no matter what, I can't find a way to overcome the issue. Any suggestion is greatly appreciated.
Last edited by papillon68 on Wed Jun 13, 2018 9:21 am, edited 1 time in total.
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: cast to subclassed widget

Post by doublemax »

What's the definition of the MyGLCanvas constructor? Most likely the first parameter is a wxFrame*. Change it to wxWindow* and it will probably work. If not, post the error message (and more code).
Use the source, Luke!
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Re: cast to subclassed widget

Post by papillon68 »

Hi and thanks for the help. I did as you suggested and the code compiles fine; however, the OpenGL canvas doesn't show anything.
In the case somebody might take a look, I'm attaching the source code (it's the pyramid sample slightly changed): I basically would like to have a wxPanel with some controls, and a separate wxPanel with the OpenGL canvas.
I'm not sure why isn't working correctly, I created both wxPanel's and added the controls accordingly. Thanks.
testingWx.zip
(30.39 KiB) Downloaded 66 times
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: cast subclassed widget

Post by Manolo »

Your issue may come from using fixed sizes and positions. Better create one or several wxsizers and let them do the windows layouts.

The layout may be something like

Code: Select all

main Frame
_____________ _____________
|   panel   | |  glcanvas  |
|           | |            |
___________________________
|       static text        |
|__________________________|
then use two wxBozSizer's:
a) sizerH horizontal, handling panel and glcanvas (there's no obvious profit in putting a glcanvas as child of a panel)
b) sizerV vertical: handles sizerH and the static text

If the panel has several controls, then use another sizer for them.
User avatar
papillon68
Earned some good credits
Earned some good credits
Posts: 118
Joined: Tue Nov 06, 2007 11:19 pm

Re: cast subclassed widget

Post by papillon68 »

Thanks Manolo that makes sense. Will follow your hints and report...
Windows 10, MS VC++ 2019 (vc142), WxWidgets 3.14
Designed with WxWidgets: https://www.facebook.com/clorofillaApp
Post Reply