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

前端 未结 6 1457
时光取名叫无心
时光取名叫无心 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:34

    I know its late by 4 yrs, but i ran into same issue & spotted this on the Qt forum for ubuntu/Mac OS.

    https://forum.qt.io/topic/7276/menu-not-showing-up-in-menubar/15

    Add the following to your main.cpp before you declare your Mainwindow w:

    QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
    

    In my case my main.cpp file now looks like:

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    AddressBook addressBook;
    AddressBookController controller (&addressBook);
    QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar); //fix for menubar notshowing in ubuntu
    
    MainWindow w(&controller);
    w.show();
    return a.exec();
    

    }

提交回复
热议问题