Qt application Menu in Window and Mac

Source: Internet
Author: User

Application Menu

Application menu in different operator systems have different designed style. Like Windows and Mac OS, they is different. In the code, we can use different Macro, Eg:q_os_mac and Q_os_win

#ifdef q_os_macvoid 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::P referencesrole);    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);}    #elsevoid 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

Qt application Menu in Window and Mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.