MenuBar Not Showing for Simple QMainWindow Code, Qt Creator Mac OS

前端 未结 6 1462
时光取名叫无心
时光取名叫无心 2020-12-10 15:29

I have been having problems adding a menu item to the built in menu bar in a Qt desktop application. I copied the code provided in the QMainWindow class reference documentat

6条回答
  •  长情又很酷
    2020-12-10 15:40

    It's pretty old Qt bug on OS X. You can work with QMenu and QMenuBar by calling QMenuBar::addAction, QMenuBar::removeAction and QMenuBar::insertAction. The trick is done by calling of QMenu::menuAction method.

    Check the code below:

    QMenu *menu = new QMenu("First menu");
    menu->addAction("item 1");
    menu->addAction("item 2");
    m_menuBar->addAction(menu->menuAction());
    

    Also you can check my another answer here with code snippet ready to compile and run.

提交回复
热议问题