edh*_*ges 5 python qt qt-designer pyside
所以基本上我想使用PySide和Qt Framework创建一个GUI应用程序.我正在使用QT设计器来进行初始UI设计.该应用程序的第一个版本将在Mac上运行,我希望它像其他Mac应用程序一样,应用程序的名称以粗体显示,并一直向左显示"关于","首选项"和"退出" .
问题是每当我添加这些类型的字符串时,下拉停止工作.
有关这方面的任何提示都会有所帮助,这是我第一次使用PySide,QT Framework和QT Designer的GUI.
下面是About
在Mac上使用C++正确使用菜单项的示例.关键是要setMenuRole
发挥正确的作用.Quit,About,Preferences和About Qt都有角色.应用程序名称以粗体显示的菜单项由操作系统提供,您无需执行任何特殊操作即可.Qt将自动移动具有正确角色的项目.您不需要做任何事情来获取退出菜单项,如果您不提供它,它会自动添加.
如果您在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();
}
Run Code Online (Sandbox Code Playgroud)