zoukankan      html  css  js  c++  java
  • Qt Application Menu In Window and Mac

    Application Menu

    Application menu in different operator systems has different designed style. like Windows and Mac os, they are different.In the code, we can use different Macro ,eg:Q_OS_MAC and Q_OS_WIN

    #ifdef Q_OS_MAC
    void MainWindow::InitMenu()
    {
        QMenuBar* mBar = menuBar();
    
        QMenu* mApp   = new QMenu(tr("App"),this);
        QMenu* mFile  = new QMenu(tr("&File"),this);
    
        mBar->addMenu(mApp);
        mBar->addMenu(mFile);
    
        /** In Mac,We should to set action role */
        QAction* actAbout = new QAction(tr("&About"),this);
        actAbout->setMenuRole(QAction::AboutRole);
    
        QAction* actSetApp = new QAction(tr("&Preference..."),this);
        actSetApp->setMenuRole(QAction::PreferencesRole);
    
        mApp->addAction(actAbout);
        mApp->addAction(actSetApp);
    
        QAction* actOpen = new QAction(tr("&Open Video Files..."),this);
        mFile->addAction(actOpen);
    
        connect(actOpen,&QAction::triggered,_player,&Player::StOpen);
        connect(actSetApp,&QAction::triggered,this,&MainWindow::StShowSetDlg);
    }
    #else
    void MainWindow::InitMenu()
    {
        QMenuBar* mBar = menuBar();
    
        QMenu* mFile  = new QMenu(tr("&File"),this);
        QMenu* mSet   = new QMenu(tr("&Setting"),this);
        QMenu* mAbout = new QMenu(tr("&About"),this);
    
        QAction* actOpen = new QAction(tr("&Open Video Files..."),this);
        QAction* actExit = new QAction(tr("&Exit out"),this);
    
        mFile->addAction(actOpen);
        mFile->addSeparator();
        mFile->addAction(actExit);
    
        QAction* actSetApp = new QAction(tr("&Setting App..."),this);
        mSet->addAction(actSetApp);
    
        mBar->addMenu(mFile);
        mBar->addMenu(mSet);
        mBar->addMenu(mAbout);
    
        connect(actOpen,&QAction::triggered,_player,&Player::StOpen);
        connect(actExit,&QAction::triggered,this,[=](){close();});
        connect(actSetApp,&QAction::triggered,this,&MainWindow::StShowSetDlg);
    }
    #endif
    

  • 相关阅读:
    239. [LeetCode ]Sliding Window Maximum
    152.[LeetCode] Maximum Product Subarray
    53. [LeetCode] Maximum Subarray
    90 [LeetCode] Subsets2
    78[LeetCode] Subsets
    练习7.52
    练习7.47、7.48、7.49、7.51
    关于类类型的隐式类型转换
    练习7.44、7.45、7.46
    练习7.36、7.37、7.39、7.40
  • 原文地址:https://www.cnblogs.com/zi-xing/p/8594799.html
Copyright © 2011-2022 走看看