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.
papillon68
Experienced Solver
Experienced Solver
Posts: 63
Joined: Tue Nov 06, 2007 11:19 pm

cast subclassed widget

Postby papillon68 » Tue Jun 12, 2018 10:08 pm

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++ 2015 (vc140), WxWidgets 3.11

User avatar
doublemax
Moderator
Moderator
Posts: 12818
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: cast to subclassed widget

Postby doublemax » Tue Jun 12, 2018 10:24 pm

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!

papillon68
Experienced Solver
Experienced Solver
Posts: 63
Joined: Tue Nov 06, 2007 11:19 pm

Re: cast to subclassed widget

Postby papillon68 » Wed Jun 13, 2018 9:20 am

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 12 times
Windows 10, MS VC++ 2015 (vc140), WxWidgets 3.11

Manolo
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 611
Joined: Mon Apr 30, 2012 11:07 pm

Re: cast subclassed widget

Postby Manolo » Wed Jun 13, 2018 3:08 pm

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.

papillon68
Experienced Solver
Experienced Solver
Posts: 63
Joined: Tue Nov 06, 2007 11:19 pm

Re: cast subclassed widget

Postby papillon68 » Wed Jun 13, 2018 3:50 pm

Thanks Manolo that makes sense. Will follow your hints and report...
Windows 10, MS VC++ 2015 (vc140), WxWidgets 3.11


Return to “C++ Development”

Who is online

Users browsing this forum: Bing [Bot] and 21 guests