wxGrid 在右侧显示大的空白边框

发布于 2024-12-13 05:05:07 字数 898 浏览 0 评论 0原文

默认情况下,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 - 问题仍然存在。

By default, wxGrid shows a small ( 10 pixels? ) blank border on the right hand side, after the last column. Calling SetMargins() has no effect on it.

It is irritating, but I can live with it.

However, if I set the the row label width to zero then the blank border grows much larger. If I have just one column, the effect is horrible. It looks like wxGrid is leaving room for the non-existent label.

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");

Is there a way to remove this border?

enter image description here

Note that if I set the size of the wxgrid window to narrower in the wxGrid constructor, hoping to hide the border, I now get a horizontal scroll bar which is horrible too.

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");

Gives me

enter image description here

I just upgraded to wxWidgets v2.8.12 - problem still exists.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹过旳痕迹 2024-12-20 05:05:07

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

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

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

编辑:我有一个工作示例,它会生成以下内容:

grid example

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< /strong>:我成功删除了剩余边距:

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

在此处输入图像描述

I didn't find an "autosize" function to fit columns in the grid space.
As a workaround, if you have only one column set its width to

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

otherwise, sum other column's width and adapt the last one to fit the remaining space (minus scrollbar width, minus 10).

EDIT: I have a working example, which produces this:

grid example

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: I succeded to remove the remaining margin with this:

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

enter image description here

云归处 2024-12-20 05:05:07

昨天解决了类似的问题,我想为以下对我有用的工作做出贡献。也许这会对其他人有所帮助:

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() 事件链接时效果特别好。

Solving something similar yesterday I would like to contribute with following what does the job for me. Perhaps this is going to help someone else:

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
    }
  }

Note: This is doing particularly well when linked with OnSize() event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文