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