我在wxFormbuilder中创建了这个简单的wxWidgets应用程序:
如您所见,功能区菜单选项卡上有一个奇怪的空白区域。有什么我想念的吗?将功能区菜单直接对齐到左上角肯定会更好。如果有人想要它,这里是由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 );
答案 0 :(得分:3)
这是wxRibbonBar
的正常行为。该空间适用于用户提供的文件菜单,或者在实施wxRibbonBar
时曾在MS Office应用程序中使用的圆形图标(请参阅http://www.corsix.org/gsoc/ribbon.html)。
在此空间中提供[现在更常见]“文件”菜单的一种方法是从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
事件绑定到处理程序函数,该函数执行您在单击“文件”时要执行的任何操作(即显示弹出菜单或整个新页面,如最新版本的办公室)。
结果是这样的: wxRibbonBar with "File" menu