Search code examples
qtuser-interfacewindowmenubar

How to enable the menubar in a QUndoView window in Qt?


I use a QUndoStack and I want to show its content using a QUndoView. I create the view as follows:

undoView = new QUndoView(&_undoStack);
undoView->setWindowTitle(tr("Undo Stack"));
undoView->show();

The view is created in a separate window (which is what I want), but that window has a disabled menu bar, so I cannot move it at all, or close it. Is there a way to enable it?


Solution

  • Ok so the issue was that the main window had a window modality of Qt::WindowModality::ApplicationModal which blocks all input to any other top-level window. Simply changing the main window to non-modal with SetWindowModality fixed this.

    hide();
    setWindowModality(Qt::WindowModality::NonModal);
    show();
    

    Alternatively change the modality directly in Qt creator if the main window was created from there.