Qt工具栏和菜单栏

时间:2011-12-11 04:43:24

标签: c++ qt custom-controls toolbar menubar

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

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

1 个答案:

答案 0 :(得分: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()));