Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMenuBar not responsive



  • Hi to everyone,
    I'm developing an application with a custom menubar. I initialize it following the qt documentation but every time that I run my application at the beginning it isn't responsive, I can't interact with the different QMenus. It becomes usable only after I Cmd+Tab to the application. Any idea on what could be causing this? This is my current code regarding the menu:

    // in views constructor initialization list:
    View(...):
      ...
      _menuBar(new QMenuBar(this)),
      _file(new QMenu(tr("&File"), _menuBar)),
      ... {}
    
    void View::createActions() {
      _newProject = new QAction(tr("&New project"), _file);
      _newProject->setShortcut(QKeySequence::New);
      _newProject->setStatusTip(tr("Create new project"));
      connect(_newProject, SIGNAL(triggered()), this, SLOT(onNewProject()));
    
      _openProject = new QAction(tr("&Open project"), _file);
      _openProject->setShortcut(QKeySequence::Open);
      _openProject->setStatusTip(tr("Open existing project"));
      connect(_openProject, SIGNAL(triggered()), this, SLOT(onOpenProject()));
    ...
    }
    
    void View::createMenus() {
    	createActions();
    
    	_file->addAction(_newProject);
    	_file->addAction(_openProject);
    
    	_menuBar->addMenu(_file);
    ...
    }
    

  • Lifetime Qt Champion

    Hi

    Which version of Qt ?
    On which OS ?



  • Hi, I'm currently working with Qt 5.9.5 on MacOS 10.15.6


  • Lifetime Qt Champion

    You should try with Qt 5.15.0.

    Are you using a QMainWindow ? If so, why not use the menu bar that comes with it ?



  • I'd like to, but it's an university project and I can only use QT 5.9.5. Previously I was using menuBar() but it had the same issue.


  • Lifetime Qt Champion

    It might be an issue with macOS 10.15.

    One thing you can do as a workaround is to disable the native macOS menu bar. You will have it on the QMainWindow but it should be usable.