WXWIDGETS试图填充整个区域

wxWidgets trying to fill whole area

本文关键字:区域 填充 WXWIDGETS      更新时间:2023-10-16

当我尝试使用wxwidgets准备GUI时,我遇到了问题。我想创建一些按钮,这些按钮涵盖文本框下的整个区域。

程序启动时看起来不错,但是当我想水平调整它时,按钮不移动。有什么想法吗?

    mainFrame::mainFrame(std::string title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600))
{
wxBoxSizer* vertSizer = new wxBoxSizer(wxVERTICAL);
vertSizer->Add(
        new wxTextCtrl(this, -1, "My text", wxDefaultPosition, wxSize(100,80), wxTE_MULTILINE),
        1, // vertically stretchable
        wxEXPAND | wxALL, // horizontally stretchable, borders all around
        10); // Add text box to parent sizer
wxBoxSizer* horizSizer = new wxBoxSizer(wxHORIZONTAL); // Make child sizer, will contain buttons
wxSizerFlags ButtonFlags(1); // Make controls stretch hoizontally (to cover entire sizer area)
ButtonFlags.Expand().Center().Border(wxALL,10); // Make controls expand vertically, add border
horizSizer->Add(new wxButton(this,123,"OK"), ButtonFlags); // Add first button
horizSizer->Add(new wxButton(this, 124,"Abort"), ButtonFlags); // Add second button
horizSizer->Add(new wxButton(this, 125,"Ignore"), ButtonFlags); // Add third button
vertSizer->Add(horizSizer); // Add child sizer to parent sizer
SetSizerAndFit(vertSizer);

}

发生这种情况,因为您没有告诉主sizer( vertSizer)生长 horizSizer以填充所有可用空间,因此您需要将 wxSizerFlags().Expand()添加到一个,但最后一行以解决此问题。

此外,使用ButtonFlags.Expand().Center()没有意义:您可以展开或居中,但不能同时进行中心,因此请选择一个。最后,DoubleBorder()Border(wxALL, 10)