GUI布局与wxSizer,wxSashWindow [英] GUI layout with wxSizer, wxSashWindow

查看:477
本文介绍了GUI布局与wxSizer,wxSashWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个窗口拆分为2,3,4 etcc不同的可调整大小的视图在mainwindow和我想实现与wxWidgets在C :: B。实际上,画布本身在所请求的数字中分割窗口,但它不会在视图的边框放置任何窗口,所以很难知道哪个视图开始在哪里和哪里结束。



我在运行时创建了一切,我打算将窗框或面板放在视图的边框上,希望在我的情况下工作,但主框架不愿意将面板和sashwidnwos放置在正确的位置,并停止处理OnSize事件。这是以前的工作代码不能正常工作,如果我在调整大小期间添加以下代码与sizers和面板。

  MainFrame * frame = new MainFrame(NULL,wxT(wxWidgets OSG Sample),
wxDefaultPosition,wxSize宽度,高度));

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);


解决方案

a href =http://docs.wxwidgets.org/stable/classwx_sash_layout_window.html =nofollow> 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);

//底部窗口
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.LayoutMDIFrame(mainFrame);
mainFrame-> Show(true);
return true;
}

为了有一个完全工作的窗口窗口你的框架必须对< a href =http://docs.wxwidgets.org/stable/classwx_sash_event.html =nofollow> EVT_SASH_DRAGGED


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);

解决方案

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

这篇关于GUI布局与wxSizer,wxSashWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆