How to get the actual size of panel?

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
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

How to get the actual size of panel?

Post by shawnee »

if I add a panel to it's parent window without set the size of this panel, how to knonw its actual size?

wxBoxSizer * vSizer = parent->GetSizer();
wxPanel * subPanel = new wxPanel(parent, "Ok", wxID_ANY, wxDefaultPosition, wxDefaultSize);
vSizer ->Add(subPanel, 0, wxEXPAND | wxALL);

wxSize sz = subPanel->GetSize();
int height = sz.GetHeight();

but hieght is always 0. :-(
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: How to get the actual size of panel?

Post by PB »

I think the sizer needs to get laid out first, after the window it belongs to is displayed/sized. In your code is probably had not yet.
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

Re: How to get the actual size of panel?

Post by shawnee »

Thanks PB!

The real things is something complicated.
I created a panel and add this panel to a wxAuiManager. Although I set a initial size for this parent panel, but the real size should be larger than the initial size because of stretch by AUI manager.

Code: Select all

    wxPanel *topPanel = new wxPanel(mainFrame);  //it's child of main frame
    wxAuiManager * PAuiManager = new wxAuiManager(topPanel, wxAUI_MGR_DEFAULT | wxAUI_MGR_TRANSPARENT_DRAG);
    
    //create system panel at the right side of main frame
    ParentPanel = new wxPanel(topPanel , wxString("SystemPanel"));  assert(ParentPanel != NULL);
    ParentPanel->SetSize(220, 308);
    
    wxAuiPaneInfo PaneInfo;
    PaneInfo.Right();
    PaneInfo.CloseButton(false);
    PaneInfo.PinButton(false);
    PaneInfo.PaneBorder(false);
    PaneInfo.MinimizeButton(false);
    PaneInfo.MaximizeButton(false);
    PaneInfo.BottomDockable(false);
    PaneInfo.TopDockable(false);
    PaneInfo.LeftDockable(false);
    PaneInfo.Layer(2).Position(1);
    PaneInfo.Caption(wxT("System")).CaptionVisible(false);
    PaneInfo.Name(wxT("System"));
    PaneInfo.MinSize(w, -1);
    PaneInfo.MaxSize(w, -1);    
    PAuiManager->InsertPane(ParentPanel, PaneInfo);

    wxBoxSizer* gs = new wxBoxSizer(wxVERTICAL);
    ParentPanel->SetSizer(gs);
    ParentPanel->Layout();
    
    //create other panels and insert into AuiManager
    ...
After main GUI display done, I want to get the real size of ParentPanel but the height is always 0.
shawnee
Experienced Solver
Experienced Solver
Posts: 78
Joined: Tue Jan 16, 2018 1:05 am

Re: How to get the actual size of panel?

Post by shawnee »

forgive my stupid, I hiden the panel in another place, so the size is always zero.
Post Reply