【问题标题】:How to add QMenuBar to QWizardPage?如何将 QMenuBar 添加到 QWizardPage?
【发布时间】:2020-04-15 07:09:52
【问题描述】:

我正在尝试将 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);

但我看不到菜单栏。

基本上我想添加一个带有“关于产品”项的“帮助”菜单来显示我们通常在许多应用程序中看到的产品版本和许可信息。我在使用 QT 5.13.2 的 Windows 10 上

【问题讨论】:

  • 您希望 QMenuBar 仅显示在 QWizardPage 中还是全部或仅在部分中显示?
  • 我希望它出现在所有向导页面上。

标签: qt qmenubar qwizardpage


【解决方案1】:

解决方案是使用设置 QMenuBar 的 QMainWindow 并将 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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    相关资源
    最近更新 更多