我正在尝试将QMenuBar添加到QWizardPage
QMenuBar *menuBar = new QMenuBar;
menuBar->setNativeMenuBar(false);
QMenu *helpMenu = new QMenu;
QAction *helpAction = new QAction;
helpMenu->addAction(helpAction);
menuBar->addMenu(helpMenu);
layout->addWidget(menuBar);
//Other widgets
setLayout(layout);
但是我看不到菜单栏。
基本上,我想添加“关于产品”项的“帮助”菜单,以显示我们通常在许多应用程序中看到的产品版本和许可信息。我在Windows 10上使用QT 5.13.2
答案 0 :(得分:2)
解决方案是使用QMainWindow,在其中设置QMenuBar并将QWizard用作centralWidget:
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
// menubar
QMenuBar * menuBar = w.menuBar();
QMenu *helpmenu = menuBar->addMenu("Help");
QAction *aboutaction = helpmenu->addAction("About product");
QObject::connect(aboutaction, &QAction::triggered, [&w](){
QMessageBox::information(&w, "About", "About");
});
QWizard *wizard = new QWizard;
// add pages
wizard->addPage(new QWizardPage);
wizard->addPage(new QWizardPage);
w.setCentralWidget(wizard);
w.show();
return a.exec();
}