问题描述
我是wxWidgets的新手,所以我正在尝试使窗口类似于CMake GUI中的窗口。如何将区域分为两个可自调整大小的区域:
我正在使用linux进行开发和cmake。 我没有使用任何UI编辑器
PS:很抱歉我的英语,这不是我的母语:o
解决方法
在CMake GUI中创建元素可扩展的框架的方法是将wxSplitterWindow与sizer一起使用,并在sizer标志构造函数中使用比例来指定每个项目应扩展多少。
这是一个简短的例子:
// For compilers that support precompilation,includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others,include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/splitter.h>
class MyFrame: public wxFrame
{
public:
MyFrame();
};
MyFrame::MyFrame()
:wxFrame(NULL,wxID_ANY,"CMake style frame",wxDefaultPosition,wxSize(600,400))
{
wxSplitterWindow* splitter = new wxSplitterWindow(this,wxDefaultSize,wxSP_LIVE_UPDATE);
wxPanel* top = new wxPanel(splitter,wxID_ANY);
wxStaticText* statText1 = new wxStaticText(top,"Where is the source");
wxTextCtrl* textCtrl1 = new wxTextCtrl(top,wxEmptyString);
wxButton* button1 = new wxButton(top,"Browse Source...");
wxBoxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL);
sizer2->Add(statText1,wxSizerFlags(0).Centre());
sizer2->Add(textCtrl1,wxSizerFlags(1).Border(wxLEFT));
sizer2->Add(button1,wxSizerFlags(0).Border(wxLEFT));
wxStaticText* statText2 = new wxStaticText(top,"Where to build the binaries:");
wxStaticText* statText3 = new wxStaticText(top,"Search:");
wxTextCtrl* textCtrl2 = new wxTextCtrl(top,wxEmptyString,wxTE_MULTILINE|wxTE_DONTWRAP);
wxStaticText* statText4 = new wxStaticText(top,"Press Configure:");
wxButton* button2 = new wxButton(top,"Configure");
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
// Now Add the items to the backfround panel's sizer:
topSizer->Add(sizer2,wxSizerFlags(0).Expand().DoubleBorder(wxALL));
topSizer->Add(statText2,wxSizerFlags(0).DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
topSizer->Add(statText3,wxSizerFlags(0).DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
// The next item is added with proportion 1 so that it will expand in size.
topSizer->Add(textCtrl2,wxSizerFlags(1).Expand().DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
topSizer->Add(statText4,wxSizerFlags(0).Center().DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
topSizer->Add(button2,wxSizerFlags(0).DoubleBorder(wxLEFT|wxRIGHT));
top->SetSizer(topSizer);
wxPanel* botton = new wxPanel(splitter,wxID_ANY);
wxTextCtrl* textCtrl3 = new wxTextCtrl(botton,wxTE_MULTILINE|wxTE_DONTWRAP);
wxBoxSizer* botomSizer = new wxBoxSizer(wxVERTICAL);
botomSizer->Add(textCtrl3,wxSizerFlags(1).Expand().DoubleBorder(wxLEFT|wxRIGHT|wxBOTTOM));
botton->SetSizer(botomSizer);
// Add the top and bottom parts to the splitter,and set the sash gravity to
// .5 so that both halfs will expand equally when the frame is resized.
splitter->SplitHorizontally(top,botton);
splitter->SetSashGravity(.5);
Layout();
}
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
::wxInitAllImageHandlers();
MyFrame* frame = new MyFrame();
frame->Show();
return true;
}
};
wxIMPLEMENT_APP(MyApp);
在Windows上,如下所示:
我还没有从CMake GUI框架中复制每个小部件,但是我认为这里有足够的信息来说明正在发生的事情。