Qt does not allow me to create a menu item named after my application with the lines “O”, “Preferences” or “Finish?”.

So basically I want to create a graphical application using PySide and Qt Framework. I use the QT constructor to create the initial user interface design. The first version of the application will work on Mac, and I want it to be similar to other Mac applications, where the application name is in bold and everything is left with "O", "Preferences" and "Exit",

The problem is that whenever I add these line types, drop down stops working.

Any advice on this subject would be helpful, this is my first GUI using PySide, QT Framework and Qt QT Designer.

+5
source share
2 answers

The following is an example of how a menu item Aboutworks correctly on a Mac, in C ++. The key to the setMenuRoleright role. There are roles for Quit, About, Preferences, and About Qt. A menu item with the application name in bold is provided by the OS, you do not need to do anything to get this. Qt automatically moves elements with the correct roles where they belong. You do not need to do anything to get the "Exit" menu item; it is automatically added if you have not provided it.

Qt Designer, menuRole QActions. , , . . Windows ( "", "", "" ), .

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();
} 
+5

Python; Mac " ", "" "", Qt ( ).

, , Qt . . About, Preferences Quit - , .

+1

All Articles