Is there a way to define a QToolbar with buttons and popup menus using Qt Designer?

Viewed 24196

I am wanting to have a toolbar in Qt that contains either QActions or QToolbarButtons that have popup menus attached to them. I have been able to do this perfectly in the code by creating a QMenu, adding it to a QToolbarButton and then adding that to the QToolbar. My issue is that this should be able to be done completely in designer.

This is what I have done via code, I want to define the buttons and menus in qt designer:
http://img402.imageshack.us/img402/7669/exmaple.png

What we are wanting to do with qt designer is to separate the code from the interface. For example this means that one person can design the form's look and components and then a programmer can take this and code the functionality behind it. We cannot accomplish this very effectively if the toolbars and menus must be designed by the programmer.

It seems like this would be a fairly common requirement for many applications, and I can't see how Qt could have forced this to be done in code instead of designer.

If anyone has any ideas as to how this is done, maybe I'm missing something in Qt?

4 Answers

2021 v6.2 ran into the same thing on a mac learning this framework and qtDesigner. Added the menu bar but didn't show up on run. I tried several above ideas and they all worked, but would like to add the qtDesigner way of enabling the menu. Select the QMenuBar and scroll down, make sure nativeMenuBar is checked. This is the same thing as manually setting this property value in mainwindow.cpp with setNativeMenuBar(false); (but of course would be redundant to do it in both places)

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->menubar->setNativeMenuBar(false);
}
Related