wxGridBagSizer and subpanel in C++

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
Mark_Aldrich
In need of some credit
In need of some credit
Posts: 4
Joined: Sat May 21, 2016 7:58 pm

wxGridBagSizer and subpanel in C++

Post by Mark_Aldrich »

I am trying to create a window, a single panel in it, and a GridBagSizer with a bunch of various sized panels in it. The problem I am having is I can not create a visible sub-panel inside the GridBagSizer.

Code: Select all

Graphics::Graphics( Configuration *Config )                                               
    {                                                                                     
    this->frame_id = TOPLEVEL;
        
    ID( NewControlId( 1 ));                                                               
    Create( NULL, ID( ), this->window_title );                                            
        
    // Set the options for the frame
    Menu( this->frame_id );                                                               
        
    // Make a panel to cover the entire client area                                       
    wxPanel *TopClientArea = new wxPanel( this, wxID_ANY );                                     
    TopClientArea->SetBackgroundColour( wxColour( wxT( "#00ffff" )));                     
                                                                                          
    // Define a layout in the client area                                                 
    wxGridBagSizer* layout = new wxGridBagSizer(0, 0);                                    
    layout->SetEmptyCellSize( wxSize( 150, 50 ));                                         
    TopClientArea->SetSizer( layout );                                                    
    SetAutoLayout( true ); 
        
    // Add a panel to the upper-left quadrant of the layout                               
    wxPanel *SubPanel = new wxPanel( TopClientArea, wxID_ANY );                           
    SubPanel->SetBackgroundColour( wxColour( wxT( "#00ff00" )));                          
    layout->Add( SubPanel, wxGBPosition(0, 0), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
    };
When I do not use SetAutoLayout, the top level window is created with a single panel, colored teal. Good so far :? , but no sign of any grid. When I do use SetAutoLayout, I get a small square in the upper left corner of the client area which is colored teal. What I want to see is a window with a teal client area, and a small green square in the upper left corner. What am I doing wrong?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGridBagSizer and subpanel in C++

Post by doublemax »

Two changes:

Code: Select all

 wxPanel *SubPanel = new wxPanel( TopClientArea, wxID_ANY, wxDefaultPosition, wxSize(32,32) );       
Create the panel with a minimum size. An empty panel has a "best" size of (0,0).

Code: Select all

TopClientArea->SetAutoLayout( true );   
The wxFrame has no sizer assigned. The TopClientArea panel has.
Use the source, Luke!
Mark_Aldrich
In need of some credit
In need of some credit
Posts: 4
Joined: Sat May 21, 2016 7:58 pm

Re: wxGridBagSizer and subpanel in C++

Post by Mark_Aldrich »

:D Thanks for the help. Problem solved!
Post Reply