Панель инструментов Qt и меню - PullRequest
0 голосов
/ 11 декабря 2011

Почему не работает эта работа? Предполагается, что он будет работать следующим образом: при нажатии «Файл» панель инструментов (не меню) отображается прямо под меню с различными кнопками, которые можно найти в меню «Файл», а при нажатии «Редактировать» Панель инструментов «Файл» скрыта, и отображается панель инструментов «Редактировать».

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 Edit

1 Ответ

0 голосов
/ 19 декабря 2011

Я сделал неверное предположение о том, что означает 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()));
...