GUI layout with wxSizer, wxSashWindow

风流意气都作罢 提交于 2019-12-25 02:26:34

问题


I'm trying to create a window which is splitted into 2, 3, 4 etcc different resizable views in mainwindow and I'd like to implement that with wxWidgets in C::B. Actually th canvas itself splits the windows in the requested numbers, but it doesn't place any sash alongn the border of views so that it's very diffciult to notice which view starts where and ends where.

I create everything on run time and I was planing to place the sash, or panels around borders of views and hoping to work in my case but the main frame is reluctant to place the panels, and sashwidnwos at the correct position and stops processing the OnSize event. That is previously working codes is not functioning properly if I add the below code with sizers and panels during resizing.

MainFrame *frame = new MainFrame(NULL, wxT("wxWidgets OSG Sample"),
        wxDefaultPosition, wxSize(width, height));

wxToolBar* toolbar = new wxToolBar(frame, wxID_ANY,wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL);

    //wxSashLayoutWindow* win = new wxSashLayoutWindow(frame, ID_WINDOW_TOP,wxPoint(50,10), wxSize(200, 30),
     //                         wxSW_3D | wxCLIP_CHILDREN);
     wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
     wxPanel* panel = new wxPanel(frame, ID_TBbutton, wxPoint(300,0), wxSize(5,500));
     panel->SetWindowStyle(wxDOUBLE_BORDER);
//   panel->SetStyle(wx_3D)
     wxPanel* panel1 = new wxPanel(frame, ID_TBbutton);
     sizer->Add( panel, 0, wxALL, 0 );
     frame->SetSizer(sizer);             
     frame->SetToolBar(toolbar);

回答1:


Please find below very basic example of MDI form with wxSashLayoutWindow:

bool SashWindowTestApp::OnInit()
{
    wxMDIParentFrame* mainFrame = new wxMDIParentFrame(NULL, ID_TEST_FRAME,
                      wxT("Sash window test"), wxPoint(0, 0), wxSize(500, 400),
                      wxDEFAULT_FRAME_STYLE);

    // top window
    wxSashLayoutWindow* topWindow = new wxSashLayoutWindow(mainFrame,
                        ID_WINDOW_TOP, wxDefaultPosition, wxSize(200, 100),
                        wxSW_3D);

    topWindow->SetDefaultSize(wxSize(1000, 100));
    topWindow->SetAlignment(wxLAYOUT_TOP);
    topWindow->SetBackgroundColour(*wxGREEN);
    topWindow->SetSashVisible(wxSASH_BOTTOM, true);

    // bottom window
    wxSashLayoutWindow* bottomWindow = new wxSashLayoutWindow(mainFrame,
                        ID_WINDOW_BOTTOM, wxDefaultPosition, wxSize(200, 200),
                        wxSW_3D);

    bottomWindow->SetDefaultSize(wxSize(1000, 200));
    bottomWindow->SetAlignment(wxLAYOUT_BOTTOM);
    bottomWindow->SetBackgroundColour(*wxYELLOW);
    bottomWindow->SetSashVisible(wxSASH_TOP, true);

    wxLayoutAlgorithm layout;
    layout.LayoutMDIFrame(mainFrame);
    mainFrame->Show(true);
    return true;
}

In order to have a fully working sash window your frame has to react on EVT_SASH_DRAGGED



来源:https://stackoverflow.com/questions/25519083/gui-layout-with-wxsizer-wxsashwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!