Reputation: 6176
i'm on Mac 10.6, i'm trying to create a menu with Qt (Creator), but the menu does not appear. I had some feed back from other pc users, and the same code seems to work on windows :
#include <QtGui>
#include "MyClass.h"
MyClass::MyClass()
{
// Create a menu
//QMainWindow::setMenuBar(new QMenuBar());
QMenu* my_menu = new QMenu("&File", this);
menuBar()->addMenu(my_menu);
}
Have you heard about this kind of problem with mac?
The toolbar works fine, but the menu doesn't.
EDIT : new code :
#include <QtGui>
#include "MMenu.h"
MMenu::MMenu()
{
QMenu* fileMenu = new QMenu("&File", this);
QMenuBar *menuBar = new QMenuBar(0);
menuBar->addMenu(fileMenu);
//menuBar()->addMenu(fileMenu);
}
Thanks
Upvotes: 2
Views: 1978
Reputation: 4357
QMenu *fileMenu = QMainWindow::menuBar()->addMenu(tr("&File"));
fileMenu->addAction(your_action);
fileMenu->addAction(your_second_action);
...
in the constructor or wherever you want it. And if you just wanna have a look at it before your main windows runs, just do
fileMenu->exec();
Upvotes: 0
Reputation: 6540
Firstly, you may be interested in the addMenu(QString) function, which returns the created QMenu in one step.
Second, try adding something to the menu. Macs may be optimizing the empty menu away. But I know this should work, I've written a program that did just fine on OSX that initialized the menus in this way.
Upvotes: 1