c++ - wxWidgets。像在 CMake GUI 中一样调整 wxFrame 中的子区域大小
问题描述
我是 wxWidgets 的新手,所以我试图让窗口像在 CMake GUI 中一样。如何将该区域划分为两个可自行调整大小的区域:
我正在使用 linux 进行开发和 cmake。我没有使用任何 UI 编辑器
PS:对不起我的英语,这不是我的母语:o
解决方案
在 CMake GUI 中创建元素扩展的框架的方法是将 wxSplitterWindow 与 sizer 一起使用,并使用 sizer flags 构造函数中的比例来指定每个项目应该扩展多少。
这是一个简短的示例:
// 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, wxID_ANY,
wxDefaultPosition, wxDefaultSize,
wxSP_LIVE_UPDATE);
wxPanel* top = new wxPanel(splitter,wxID_ANY);
wxStaticText* statText1 = new wxStaticText(top, wxID_ANY,
"Where is the source");
wxTextCtrl* textCtrl1 = new wxTextCtrl(top, wxID_ANY, wxEmptyString);
wxButton* button1 = new wxButton(top, wxID_ANY, "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 ,wxID_ANY, "Where to build the binaries:");
wxStaticText* statText3 = new wxStaticText(top, wxID_ANY, "Search:");
wxTextCtrl* textCtrl2 = new wxTextCtrl(top, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE|wxTE_DONTWRAP);
wxStaticText* statText4 = new wxStaticText(top, wxID_ANY, "Press Configure:");
wxButton* button2 = new wxButton(top, wxID_ANY, "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, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
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 框架中复制每个小部件,但我认为那里有足够的内容可以让您了解正在发生的事情。
推荐阅读
- outlook - 在 Microsoft 365 中为大量用户自动化共享邮箱
- streaming - Grpc-gateway 对 com.google.protobuf.wrappers.StringValue 结果进行奇怪的包装
- python - elif 不适用于字典键值对
- shell - 从 Jenkins Pipeline 执行 shell 脚本
- linux - 如何使用 dd 和 zgrep 命令在大压缩日志文件中进行搜索?
- serverless-framework - 在 Lambda@Edge 上使用 Sharp 处理大图像
- r - 在 R 中使用 Rex 包解析服务器日志
- mysql - SQL 查询返回随机选择,但根据值进行拆分
- android - 由于谷歌分析,android webview中的网页自动刷新而无需用户操作
- apache - Apache 使用 www 和非 www