【问题标题】:wxGrid shows large empty border on rightwxGrid 在右侧显示大的空白边框
【发布时间】:2011-10-30 18:12:28
【问题描述】:

默认情况下,wxGrid 在右侧最后一列之后显示一个小的(10 像素?)空白边框。调用 SetMargins() 对其没有影响。

这很烦人,但我可以忍受。

但是,如果我将行标签宽度设置为零,则空白边框会变得更大。如果我只有一列,效果会很糟糕。看起来 wxGrid 正在为不存在的标签留出空间。

myPatGrid = new wxGrid(panel,IDC_PatGrid,wxPoint(10,10),wxSize(150,300) );
myPatGrid->SetRowLabelSize(0); 
myPatGrid->CreateGrid(200,1);
myPatGrid->SetColLabelValue(0,L"Patient IDs");

有没有办法去掉这个边框?

请注意,如果我在 wxGrid 构造函数中将 wxgrid 窗口的大小设置为更窄,希望隐藏边框,我现在会得到一个水平滚动条,这也太可怕了。

myPatGrid = new wxGrid(panel,IDC_PatGrid,wxPoint(10,10),wxSize(100,300) );
myPatGrid->SetRowLabelSize(0); 
myPatGrid->CreateGrid(200,1);
myPatGrid->SetColLabelValue(0,L"Patient IDs");

给我

我刚刚升级到 wxWidgets v2.8.12 - 问题仍然存在。

【问题讨论】:

    标签: wxwidgets


    【解决方案1】:

    我没有找到“自动调整大小”功能来适应网格空间中的列。 作为一种解决方法,如果您只有一列,请将其宽度设置为

    myPatGrid->SetColMinimalWidth(0, grid_width - wxSYS_VSCROLL_X - 10)
    

    否则,求和其他列的宽度并调整最后一个以适应剩余空间(减去滚动条宽度,减去 10)。

    编辑:我有一个工作示例,它产生了这个:

    int gridSize = 150;
    int minSize = gridSize - wxSYS_VSCROLL_X - 2; // scrollbar appear if higher
    grid->SetRowLabelSize(0);
    grid->SetColMinimalWidth(0, minSize);
    grid->SetColSize(0, minSize); // needed, otherwise column will not resize
    grid->ForceRefresh();
    grid->SetColLabelValue(0, "COORD");
    

    EDIT2:我成功删除了剩余边距:

    int gridSize = 150;
    int minSize = gridSize - 16; // trial & error
    grid->SetMargins(0 - wxSYS_VSCROLL_X, 0);
    

    【讨论】:

    • @ravenspoint,如果你还需要解决这个问题,明天我会尝试一个工作示例
    • 我仍然需要解决这个问题 - 它破坏了我的几个应用程序的外观。
    • 这与我遇到的问题相同。
    • @ravenspoint:你想去掉滚动条之前右边的小边框吗?因为你说“这很烦人,但我可以忍受。”
    • 我不得不忍受它,但如果没有它,它看起来会更加整洁和专业。
    【解决方案2】:

    昨天解决了类似的问题,我想通过关注对我来说工作的内容做出贡献。也许这会对其他人有所帮助:

    void RecalculateGridSize(wxGrid *grid, int cols) {
      if (grid == NULL)
        return;
    
      grid->AutoSizeColumns();
    
      float cumulative = 0, param = 0;
      for (int i = 0; i < cols; ++i)
        cumulative += grid->GetColSize(i);
    
      //not stretching when client size lower then calculated
      if(grid->GetClientSize().x < cumulative)
        return;
    
      param = (float) grid->GetClientSize().x / cumulative;
    
      for (int i = 0; i < cols; ++i) {
        if (i != cols - 1)
          grid->SetColSize(i, int(grid->GetColSize(i)*param) - 2); //-2 for each line per column
        else
          grid->SetColSize(i, int(grid->GetColSize(i)*param)); //leaving last column full to fill properly
        }
      }
    

    注意:这在与 OnSize() 事件关联时效果特别好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 2013-11-05
      • 1970-01-01
      • 2021-07-07
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多