2011-12-11 132 views
0

为什么不做这项工作?它应该是这样工作的:当单击“文件”时,工具栏(不是菜单栏)显示在菜单栏下方,菜单栏上有不同的按钮,可以在“文件”菜单中找到,当单击“编辑”时, “文件”工具栏被隐藏,并显示“编辑”工具栏。Qt工具栏和菜单栏

menubar = new MyMenuBar(this);//this is a menubar with "file" and "edit" 
menubar->setGeometry(0,0,1100,30); 

ftoolbar = new MyFileToolBar(this); // this is a toolbar with buttons that would be 
// found in a "file" menu 
ftoolbar->setGeometry(0,30,1100,40); 
ftoolbar->hide(); 

etoolbar = new MyEditToolBar(this); // this is a toolbar with buttons that would be 
//found in an "edit" menu 
etoolbar->setGeometry(0,30,1100,40); 
etoolbar->hide(); 

//here down does not work 
connect(menubar->File, SIGNAL(aboutToShow()), ftoolbar, SLOT(show())); 
connect(menubar->File, SIGNAL(aboutToHide()), ftoolbar, SLOT(hide())); 


connect(menubar->Edit, SIGNAL(aboutToShow()), etoolbar, SLOT(show())); 
connect(menubar->Edit, SIGNAL(aboutToHide()), etoolbar, SLOT(hide())); 

文件 File 编辑Edit

+0

没关系!我解决了它,但由于某种原因,stacko不让我回答我的问题......所以不要回答。我用aboutToShow()替换触发(QAction *) –

+0

我有兴趣看到菜单栏内的工具栏的屏幕截图。 – 2011-12-11 07:23:21

+0

@Sosukodo:在​​菜单栏下方(正常位置)。不在里面。 – TonyK

回答

0

我做了什么triggered(QAction*)意味着坏的假设。

我更换

connect(menubar->File, SIGNAL(triggered(QAction*)), ftoolbar, SLOT(show())); 
connect(menubar->File, SIGNAL(triggered(QAction*)), ftoolbar, SLOT(hide())); 


connect(menubar->Edit, SIGNAL(triggered(QAction*)), etoolbar, SLOT(show())); 
connect(menubar->Edit, SIGNAL(triggered(QAction*)), etoolbar, SLOT(hide())); 

connect(menubar->File, SIGNAL(aboutToShow()), ftoolbar, SLOT(show())); 
connect(menubar->File, SIGNAL(aboutToHide()), ftoolbar, SLOT(hide())); 


connect(menubar->Edit, SIGNAL(aboutToShow()), etoolbar, SLOT(show())); 
connect(menubar->Edit, SIGNAL(aboutToHide()), etoolbar, SLOT(hide()));