2011-10-30 32 views
3

默認情況下,wxGrid在右側顯示一個小的(10像素?)空白邊框,位於最後一列之後。調用SetMargins()對它沒有影響。wxGrid在右側顯示大的空邊框

這很刺激,但我可以忍受它。

但是,如果將行標籤寬度設置爲零,則空白邊框會變得更大。如果我只有一列,效果非常糟糕。它看起來像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"); 

有沒有辦法刪除這個邊框?

enter image description here

需要注意的是,如果我設置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"); 

給我

enter image description here

我剛剛升級到wxWidgets的v2.8.12 - 問題依然存在。

回答

1

我沒有找到「autosize」函數來適應網格空間中的列。 作爲一種解決辦法,如果你只有一個列的寬度設置爲

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

否則,總和其他列的寬度和適應的最後一個適應的剩餘空間(減去滾動條寬度減去10)。

EDIT:我有一個工作實施例中,其產生這樣的:

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:我succeded與此除去剩餘的餘量:

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

enter image description here

+0

我試過了。它似乎沒有任何區別。 – ravenspoint

+0

@ravenspoint,明天我會嘗試一個工作的例子,如果你仍然需要解決這個問題 – Sga

+0

我仍然需要解決這個問題 - 它毀壞我的幾個應用程序的外觀。 – ravenspoint

0

昨天解決類似的事情,我想貢獻下面的工作對我來說是什麼。也許這將幫助其他人:

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()事件鏈接時特別好。