So basically I want to create a GUI app using PySide and the Qt Framework. I am using the QT designer to make the initial UI design. The first version of the app will run on Mac and I want it to be like other Mac applications where the name of the app is in bold and all the way to the left with an "About", "Preferences", and "Quit".
The problem is that whenever I add these types of strings the drop down stops working.
Any tips on this would be helpful this is my first GUI using PySide, QT Framework, andd QT Designer.
Below is an example of getting the About
menu item working correctly on Mac, in C++. The key is to setMenuRole
to the correct role. There are roles for Quit, About, Preferences, and About Qt. The menu item with application's name in bold is provided by the OS, you don't need to do anything special to get that. Qt will automatically move items with correct roles where they belong. You don't need to do anything to get the Quit menu item, it's added automatically if you don't provide one.
If you're making menus in Qt Designer, you simply set the menuRole
property of those menu QActions. That is all that's needed for the menus to go to correct places. Do not add a menu with your application's name. Simply create usual Windows-style menus (File, Edit, Help), and the items will be rearranged appropriately to their roles.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationVersion(...);
a.setOrganizationName(...);
a.setOrganizationDomain(...);
a.setApplicationName(...);
MainWidget w; // MainWidget is your widget class
QMessageBox * aboutBox = new QMessageBox(&w);
QImage img(":/images/youricon.png");
aboutBox->setIconPixmap(QPixmap::fromImage(
img.scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
QString txt;
txt = txt.fromUtf8(
"fooapp %1\nCopyright \xC2\xA9 2012 Ed Hedges\n"
"Licensed under the terms of ....");
txt = txt.arg(a.applicationVersion());
aboutBox->setText(txt);
QMenuBar menu;
QMenu * submenu = menu.addMenu("Help");
QAction * about = submenu->addAction("About", aboutBox, SLOT(exec()));
about->setMenuRole(QAction::AboutRole);
w.show();
return a.exec();
}
I don't know about Python; but on the Mac you create About, Preferences or Quit menu items and Qt will automatically shift them into the application menu on the left (the one with the bold text).
I'm guessing that you are trying to create your own application menu and Qt is getting confused. You don't need to create it. Put your About, Preferences or Quit menu items under File or some other menu heading and they will get shifted.