1

我用 gcc 和 wxSmith 构建的 wxWidgets 程序有几个带有文本和按钮的大小调整器、一个 wxMathPlot 窗口和一个 wxGrid。当我在选择中选择某些内容时,网格会填充不同数量的信息,并在必要时增加更多行或删除不必要的行。当我从 1 行开始时,当做出选择时,仍然会显示一行,但是一旦我触摸窗口的边框来调整它的大小,所有的东西都会被调整大小。网格会增长,因此每一行都没有滚动条显示,并且绘图窗口会根据网格留下的空间大小而增大或缩小。是否有可能对这种行为进行编码,因此每次网格获得新输入时都会调用它?我试过了

UserGrid->Fit();
SendSizeEvent();

在网格方法的末尾,但这不起作用。我有OnResize()如下方法:

void Lizenz_Logfile_ReaderFrame::OnResize(wxSizeEvent& event)
{
    DoGetBestSize();
    UserGrid->Fit();
    //UserGrid->Refresh();
    Layout();

}

这是我的布局(以防我尝试的某些设置创建了想要的行为)

 //(*Initialize(Lizenz_Logfile_ReaderFrame)
    wxBoxSizer* BoxSizer4;
    wxMenuItem* MenuItem2;
    wxFlexGridSizer* FlexGridSizer3;
    wxMenuItem* MenuItem1;
    wxFlexGridSizer* FlexGridSizer5;
    wxBoxSizer* BoxSizer2;
    wxMenu* Menu1;
    wxBoxSizer* BoxSizer1;
    wxMenuBar* MenuBar1;
    wxFlexGridSizer* FlexGridSizer6;
    wxMenu* Menu2;

    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE|wxFULL_REPAINT_ON_RESIZE, _T("wxID_ANY"));
    SetClientSize(wxSize(525,713));
    Panel4 = new wxPanel(this, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL4"));
    BoxSizer1 = new wxBoxSizer(wxVERTICAL);
    BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
    LogFilePickerCtrl = new wxFilePickerCtrl(Panel4, ID_FILEPICKERCTRL2, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_USE_TEXTCTRL, wxDefaultValidator, _T("ID_FILEPICKERCTRL2"));
    BoxSizer2->Add(LogFilePickerCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(BoxSizer2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    FlexGridSizer5 = new wxFlexGridSizer(0, 3, 0, 0);
    RadioButtonProe = new wxRadioButton(Panel4, ID_RADIOBUTTON4, _("PROE"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP, wxDefaultValidator, _T("ID_RADIOBUTTON4"));
    FlexGridSizer5->Add(RadioButtonProe, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    RadioButtonEng = new wxRadioButton(Panel4, ID_RADIOBUTTON5, _("ENG"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON5"));
    FlexGridSizer5->Add(RadioButtonEng, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    RadioButtonUi = new wxRadioButton(Panel4, ID_RADIOBUTTON6, _("UI"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON6"));
    FlexGridSizer5->Add(RadioButtonUi, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText7 = new wxStaticText(Panel4, ID_STATICTEXT1, _("Label"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
    FlexGridSizer5->Add(StaticText7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    ChoiceDate = new wxChoice(Panel4, ID_CHOICE3, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE3"));
    FlexGridSizer5->Add(ChoiceDate, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(FlexGridSizer5, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    FlexGridSizer6 = new wxFlexGridSizer(0, 3, 0, 0);
    StaticText10 = new wxStaticText(Panel4, ID_STATICTEXT20, _("Durchschnittlich genutzte Lizenzen \nam Tag"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT20"));
    FlexGridSizer6->Add(StaticText10, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticTextDurchschnitt = new wxStaticText(Panel4, ID_STATICTEXT21, _("Anzahl"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT21"));
    FlexGridSizer6->Add(StaticTextDurchschnitt, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    FlexGridSizer6->Add(-1,-1,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText12 = new wxStaticText(Panel4, ID_STATICTEXT22, _("Maximum genutzte Lizenzen"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT22"));
    FlexGridSizer6->Add(StaticText12, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticTextMaximum = new wxStaticText(Panel4, ID_STATICTEXT23, _("Anzahl"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT23"));
    FlexGridSizer6->Add(StaticTextMaximum, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticTextMaximumTime = new wxStaticText(Panel4, ID_STATICTEXT24, _("Wann"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT24"));
    FlexGridSizer6->Add(StaticTextMaximumTime, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText15 = new wxStaticText(Panel4, ID_STATICTEXT25, _("Minimum genutzte Lizenzen"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT25"));
    FlexGridSizer6->Add(StaticText15, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticTextMinimum = new wxStaticText(Panel4, ID_STATICTEXT26, _("Anzahl"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT26"));
    FlexGridSizer6->Add(StaticTextMinimum, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticTextMinimumTime = new wxStaticText(Panel4, ID_STATICTEXT27, _("Wann"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT27"));
    FlexGridSizer6->Add(StaticTextMinimumTime, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(FlexGridSizer6, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
    MathPlot1 = new mpWindow(Panel4, ID_MATHPLOT2, wxDefaultPosition, wxDefaultSize, wxRAISED_BORDER|wxTAB_TRAVERSAL);
    xAxis = new mpScaleX(_("Time"), 1, true);
    MathPlot1->AddLayer(xAxis);
    yAxis = new mpScaleY(_("Licenses"), 4, true);
    MathPlot1->AddLayer(yAxis);
    VectorLicenses = new mpFXYVector(_("Licenses"), 0);
    VectorLicenses->SetContinuity(true);
    MathPlot1->AddLayer(VectorLicenses);
    VectorUser = new mpFXYVector(_("User"), 0);
    VectorUser->SetContinuity(true);
    MathPlot1->AddLayer(VectorUser);
    MathPlot1->UpdateAll();
    MathPlot1->Fit();
    BoxSizer4->Add(MathPlot1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(BoxSizer4, 2, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    FlexGridSizer3 = new wxFlexGridSizer(0, 3, 0, 0);
    StaticText9 = new wxStaticText(Panel4, ID_STATICTEXT12, _("User\nFür Statistik Lizenz oben wählen"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT12"));
    FlexGridSizer3->Add(StaticText9, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    ChoiceUser = new wxChoice(Panel4, ID_CHOICE2, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE2"));
    FlexGridSizer3->Add(ChoiceUser, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    FlexGridSizer3->Add(-1,-1,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText4 = new wxStaticText(Panel4, ID_STATICTEXT13, _("Durchschnittliche Zeit \nLizenznutzung pro Tag"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT13"));
    FlexGridSizer3->Add(StaticText4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticTextStundenDurchschnitt = new wxStaticText(Panel4, ID_STATICTEXT14, _("Betrag"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT14"));
    FlexGridSizer3->Add(StaticTextStundenDurchschnitt, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText1 = new wxStaticText(Panel4, ID_STATICTEXT15, _("Stunden"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT15"));
    FlexGridSizer3->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText8 = new wxStaticText(Panel4, ID_STATICTEXT16, _("Tag mit Stundenmaximum"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT16"));
    FlexGridSizer3->Add(StaticText8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticTextStundenMax = new wxStaticText(Panel4, ID_STATICTEXT17, _("Stunden"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT17"));
    FlexGridSizer3->Add(StaticTextStundenMax, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticTextTagMax = new wxStaticText(Panel4, ID_STATICTEXT18, _("Tag"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT18"));
    FlexGridSizer3->Add(StaticTextTagMax, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(FlexGridSizer3, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    UserGrid = new wxGrid(Panel4, ID_GRID1, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE, _T("ID_GRID1"));
    UserGrid->CreateGrid(1,5);
    UserGrid->EnableEditing(false);
    UserGrid->EnableGridLines(true);
    UserGrid->SetColLabelValue(0, _("Lizenz"));
    UserGrid->SetColLabelValue(1, _("Tag"));
    UserGrid->SetColLabelValue(2, _("Von"));
    UserGrid->SetColLabelValue(3, _("Bis"));
    UserGrid->SetColLabelValue(4, _("Nutzungszeit"));
    UserGrid->SetDefaultCellFont( UserGrid->GetFont() );
    UserGrid->SetDefaultCellTextColour( UserGrid->GetForegroundColour() );
    BoxSizer1->Add(UserGrid, 0, wxEXPAND|wxALIGN_LEFT|wxALIGN_TOP, 0);
    Panel4->SetSizer(BoxSizer1);
    BoxSizer1->Fit(Panel4);
    BoxSizer1->SetSizeHints(Panel4);
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);

    Connect(ID_FILEPICKERCTRL2,wxEVT_COMMAND_FILEPICKER_CHANGED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnLogFilePickerCtrlFileChanged1);
    Connect(ID_RADIOBUTTON4,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnRadioButtonProeSelect);
    Connect(ID_RADIOBUTTON5,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnRadioButtonEngSelect);
    Connect(ID_RADIOBUTTON6,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnRadioButtonUiSelect);
    Connect(ID_CHOICE3,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnChoiceDateSelect);
    Connect(ID_CHOICE2,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnChoiceUserSelect);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnAbout);
    //*)

有没有办法让窗口调整大小以便完全显示网格?


编辑:正如我在调试时发现的那样,OnResize()在实际调整窗口大小时永远不会被调用。它必须在后台完成,因为我不会对我的窗口大小做任何其他事情。


编辑 2:经过相当多的尝试后,使用UserGrid->AppendRow()网格后似乎不能很好地重新绘制。在此行之后,之前可见的滚动条会消失,并且只有在用户调整窗口大小时才会重新出现。我已经尝试过UserGrid->AdjustScrollbars()之后UserGrid->ForceRefresh()没有效果。

4

2 回答 2

3

http://docs.wxwidgets.org/trunk/overview_windowsizing.html中,wxWidgets 提供了两种主要的调整大小的方法:

  • wxWindow::Fit() 设置窗口的大小以适合其子项。添加每个子窗口的大小,然后此父窗口更改其大小以适合所有子窗口。
  • wxWindow::Layout() 相反。孩子们会根据 sizer 规则改变他们的大小,这样他们就可以适应他们父母的可用空间。[...] 是容器窗口的默认 EVT_SIZE 处理程序所调用的内容

因为网格可以有数千行/列,所以它的大小可能很大。不要试图告诉父母适应它。您最好为网格(或其大小调整器)设置最大和最小尺寸,然后在每次更改行数/列数或其大小时使用 Fit() 或 Layout()。

于 2017-01-16T20:22:36.027 回答
0

用户网格->适合();对我有用,但我必须使用no minimum size。由于设置了最小尺寸 Fit() 不会做出任何改变。此外,如果 Fit 计算的尺寸大于预设的最小尺寸,它不会改变尺寸。当我使用默认(-1)最小尺寸时,它开始工作。

于 2021-10-08T09:28:33.790 回答