2016-05-31 95 views
0

我wxFormbuilder創建這個簡單的wxWidgets應用:絲帶菜單空白處

screenshot

正如你所看到的,有色帶上的菜單選項卡的奇怪的空白。有什麼我失蹤?如果讓功能區菜單直接排列在左上方,將會更好。如果有人需要它,這裏是wxFormbuilder生成的代碼:

this->SetSizeHints(wxSize(183,146), wxDefaultSize); 

wxBoxSizer* bSizer4; 
bSizer4 = new wxBoxSizer(wxVERTICAL); 

m_ribbonBar1 = new wxRibbonBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxRIBBON_BAR_DEFAULT_STYLE); 
m_ribbonBar1->SetArtProvider(new wxRibbonAUIArtProvider); 
m_ribbonPage1 = new wxRibbonPage(m_ribbonBar1, wxID_ANY, wxT("File") , wxNullBitmap , 0); 
m_ribbonBar1->SetActivePage(m_ribbonPage1); 
m_ribbonPanel1 = new wxRibbonPanel(m_ribbonPage1, wxID_ANY, wxT("File") , wxNullBitmap , wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_DEFAULT_STYLE); 
m_rbtnBar = new wxRibbonButtonBar(m_ribbonPanel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0); 
m_rbtnBar->AddButton(wxID_ANY, wxT("New"), wxNullBitmap, wxEmptyString); 
m_rbtnBar->AddButton(wxID_ANY, wxT("Save"), wxNullBitmap, wxEmptyString); 
m_rbtnBar->AddButton(wxID_ANY, wxT("Load"), wxNullBitmap, wxEmptyString); 
m_ribbonPage2 = new wxRibbonPage(m_ribbonBar1, wxID_ANY, wxT("View") , wxNullBitmap , 0); 
m_ribbonBar1->SetActivePage(m_ribbonPage2); 
m_ribbonPanel21 = new wxRibbonPanel(m_ribbonPage2, wxID_ANY, wxT("View") , wxNullBitmap , wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_DEFAULT_STYLE); 
m_ribbonButtonBar21 = new wxRibbonButtonBar(m_ribbonPanel21, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0); 
m_ribbonButtonBar21->AddButton(wxID_ANY, wxT("Do something"), wxNullBitmap, wxEmptyString); 
m_ribbonButtonBar21->AddButton(wxID_ANY, wxT("Do something else"), wxNullBitmap, wxEmptyString); 
m_ribbonBar1->Realize(); 

bSizer4->Add(m_ribbonBar1, 0, wxEXPAND, 5); 

wxBoxSizer* mainSizer; 
mainSizer = new wxBoxSizer(wxVERTICAL); 

m_ntbkMain = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0); 
m_panel1 = new wxPanel(m_ntbkMain, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); 
wxBoxSizer* bSizer6; 
bSizer6 = new wxBoxSizer(wxHORIZONTAL); 

wxBoxSizer* bSizer7; 
bSizer7 = new wxBoxSizer(wxVERTICAL); 

m_button11 = new wxButton(m_panel1, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0); 
bSizer7->Add(m_button11, 0, wxALL, 5); 

m_button12 = new wxButton(m_panel1, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0); 
bSizer7->Add(m_button12, 0, wxALL, 5); 

m_button13 = new wxButton(m_panel1, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0); 
bSizer7->Add(m_button13, 0, wxALL, 5); 


bSizer6->Add(bSizer7, 1, wxEXPAND, 5); 


m_panel1->SetSizer(bSizer6); 
m_panel1->Layout(); 
bSizer6->Fit(m_panel1); 
m_ntbkMain->AddPage(m_panel1, wxT("Tab 1"), true); 
m_panel2 = new wxPanel(m_ntbkMain, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); 
m_ntbkMain->AddPage(m_panel2, wxT("a page"), false); 
m_panel3 = new wxPanel(m_ntbkMain, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); 
m_ntbkMain->AddPage(m_panel3, wxT("a page"), false); 
m_panel4 = new wxPanel(m_ntbkMain, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); 
m_ntbkMain->AddPage(m_panel4, wxT("a page"), false); 

mainSizer->Add(m_ntbkMain, 1, wxEXPAND, 5); 


bSizer4->Add(mainSizer, 1, wxEXPAND, 5); 


this->SetSizer(bSizer4); 
this->Layout(); 

this->Centre(wxBOTH); 

這就是我想要實現:

office 2007 button

+1

什麼你是WX和Windows版本?你能在樣本中重現嗎? – Igor

+0

@Igor Windows 10教育版64位,源自wxWidgets 3.1.0。我還沒有嘗試過,這只是它在wxFormbuilder設計器中的樣子。 – calcyss

+0

試試這個例子。如果有效,請查看與您的代碼有什麼不同。如果沒有 - 那麼,發佈到wx-dev或在trac.wxwidgets.org上打開一張票。另外,嘗試實際編譯的應用程序二進制文件 - 有時RAD工具可能會引起誤解。 – Igor

回答

3

這是wxRibbonBar正常行爲。該空間用於用戶提供的文件菜單,或者實施wxRibbonBar(見http://www.corsix.org/gsoc/ribbon.html)時曾用於MS Office應用程序的圓形圖標。

在此空間中提供[現在更常見]的「文件」菜單的一種方法是從wxRibbonMSWArtProvider(或其他提供者之一)派生自己的藝術提供者。您需要覆蓋::DrawTabCtrlBackground

下面是一個簡單的例子:

void myArtProvider::DrawTabCtrlBackground(
         wxDC& dc, 
         wxWindow* WXUNUSED(wnd), 
         const wxRect& rect) 
{ 
    // Draw the background for the whole tab area. 
    dc.SetPen(*wxTRANSPARENT_PEN); 
    dc.SetBrush(m_tab_ctrl_background_brush); 
    dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); 

    // Draw the "File" menu background, unfortunately its static and doesn't change when hovered. 
    dc.SetBrush (wxColour(35, 70, 135)); 
    dc.DrawRectangle (rect.x, rect.y, 60, rect.height); 
    dc.SetFont (m_tab_label_font); 

    // Centre the "File" text in the available space (alternatively this could use wxDC::DrawLabel). 
    dc.SetTextForeground (*wxWHITE); 
    int text_height; 
    int text_width; 
    dc.GetTextExtent ("File", &text_width, &text_height); 
    int y = rect.y + ((rect.height - text_height)/2); 

    // Draw the "File" text. 
    dc.DrawText("File", rect.x + ((60 - text_width)/2) + 1, y); 
} 

然後需要綁定wxRibbonBar wxEVT_LEFT_DOWN事件處理函數,做任何你想要的,當你點擊「文件」的情況發生(即顯示一個彈出菜單或像最新版Office一樣的全新頁面)。

的結果是這樣的: wxRibbonBar with "File" menu

+0

我怎樣才能在窗口的角落得到一個像辦公室一樣的按鈕? – calcyss

+0

請你可以添加一個圖像到你的問題,顯示你想達到什麼。你的意思是一種漸變按鈕,而不是我展示的平面按鈕? – iwbnwif

+0

我更新了問題。對不起,我的意思是office-2007-like。 – calcyss