【问题标题】:Notifying wxSizer of dynamic layout changes通知 wxSizer 动态布局更改
【发布时间】:2021-12-22 01:17:09
【问题描述】:

我有以下布局层次结构:

wxMDIChildFrame -> wxNotebook -> wxScrolledWindow -> wxBoxSizer -> wxStyledTextCtrl

目标: wxStyledTextCtrl (CScriptWnd) 会在用户添加或删除一行或按 Shift+Enter 将另一个 CScriptWnd 添加到 wxScrolledWindow 时自行调整大小。

下面的代码是添加一行的时候:

void CScriptWnd::OnNewLineAdded(wxStyledTextEvent& event)
{
    long col, line;
    PositionToXY(GetInsertionPoint(), &col, &line);

    auto ClientSize = GetClientSize();
    int Height = ClientSize.GetHeight();

    Height += TextHeight(line);

    SetClientSize(ClientSize.GetWidth(), Height);
    SetMinSize(wxSize(ClientSize.GetWidth(), Height));


    Refresh();
    
    //m_ParentWindow->FitInside(); //CScriptWnd gets smaller rather than larger
    //m_ParentWindow->Layout(); //CScriptWnd gets smaller rather than larger
    //m_ParentWindow->GetGrandParent()->Layout(); //No effect


    event.Skip();
}

大多数工作都很好,例如 CScriptWnd 自行调整大小,添加到 wxScrolledWindow 的新脚本窗口等...

问题是用户界面的更新只有在使用鼠标调整 wxMDIChildFrame 的大小时才会正确发生。 例如,如果有两个CScriptWnd 并且顶部的自己调整大小,它会与底部的重叠 直到使用鼠标调整 wxMDIChildFrame 的大小。滚动条的可见性也发生了类似的情况,当CScriptWnd 客户端大小变大时,滚动条只有在使用鼠标调整顶级窗口大小时才可见。

不知道我错过了什么。

【问题讨论】:

  • 到目前为止GetParent()->FitInside() 似乎提供了最好的效果。 CScriptWnd 的增长和缩小没有任何问题,也没有任何重叠,滚动条会自动出现或消失。

标签: c++ wxwidgets


【解决方案1】:

你可能需要

SetMinSize(GetSize());
GetParent()->Layout();

【讨论】:

  • 它解决了“如果有两个 CScriptWnd 并且顶部的自己调整大小,它与底部的重叠,直到使用鼠标调整 wxMDIChildFrame 的大小。”部分。然而,现在发生的是CScriptWnd 仅增长到wxMDIChildFrame 的客户端大小,然后出现CScriptWnd 滚动条。所以CScriptWnd 的大小限制为 wxMDIChildFrame 客户端高度。 wxMDIChildFrame 的滚动条也仅在我使用鼠标调整框架大小时出现。我想要的是CScriptWnd 尽可能地增长或缩小。
  • @macroland grows or shrinks as much as it can - mdi child 的大小是“尽可能多”的大小。
  • @Igor 即使被 wxScrolledWindow 拥有?
  • “我想要的是 CScriptWnd 尽可能地增长或缩小” 我不明白。根据新添加的行,它是否应该无限增长?或者增长到某种规模(受 MDI 的客户端规模或其他限制)?
  • @catalin,是的,它可以增长到用户需要(100 行,也许 1000 行),当行被删除时它会缩小(类似于 Jupyter 笔记本)。 wxScrolledWindow 在这里使用滚动条完成这项工作,因此可以添加任意数量的行,并且当滚动 CScriptWnd 的开头或结尾时可以看到,CScriptWnd 不应该有任何自己的滚动条。当然可以定义最大限制,但不受 MDI 客户端大小的限制。正如我在原帖中评论的那样,GetParent()->FitInside() 似乎提供了最好的效果。
猜你喜欢
  • 2013-08-24
  • 2015-08-30
  • 2015-06-26
  • 1970-01-01
  • 2012-12-20
  • 1970-01-01
  • 2012-07-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多