Stacking QPushButtons on the other side of a QMenuBar

▼魔方 西西 提交于 2019-12-05 10:24:18

QMenuBar has a setCornerWidget function, that sets a widget (that may include a whole layout) as the cornet widget.

QMainWindow::setMenuWidget() can be used to set any widget as the main window's menu bar widget. Using an appropriate layout, you can use something like the following to customize the menu bar (MainWindowImpl is a sub class of QMainWindow):

void MainWindowImpl::setupMenubar() {
    QWidget* menuWidget = new QWidget(this);

    QGridLayout* menuWidgetLayout = new QGridLayout(menuWidget);
    menuWidget->setLayout(menuWidgetLayout);

    // Add the menu bar and all tool buttons to the widget
    menuWidgetLayout->addWidget(theMenubar, 0, 0, 1,1);
    menuWidgetLayout->addWidget(new QToolButton(), 0, 1, 1, 1);
    menuWidgetLayout->addWidget(new QToolButton(), 0, 2, 1, 1);

    // set the custom widget as the main window's menu widget
    setMenuWidget(menuWidget);
}

theMenubar points to the QMenuBar which contains your application's main menu bar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!