【问题标题】:wxWidgets trying to fill whole areawxWidgets 试图填满整个区域
【发布时间】:2016-11-30 14:24:27
【问题描述】:

我在尝试使用 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);

}

【问题讨论】:

    标签: c++ wxwidgets


    【解决方案1】:

    发生这种情况是因为您没有告诉您的主大小调整器 (vertSizer) 增大 horizSizer 以填充所有可用空间,您需要将 wxSizerFlags().Expand() 添加到最后一行来解决此问题。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      相关资源
      最近更新 更多