From 916863dd0a49bc65c71ae9ae859e4ed8070f6e51 Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Wed, 29 Jul 2015 14:55:55 +0100 Subject: [PATCH] Force creation of native menu bar when main window is shown Native menu bar recreation is hooked up to the focusWindowChanged signal in QGuiApplication. Emittng this when the window is shown ensures that Qt creates the menubar at the correct time. Fixes gh2k/fractorium#1 --- Source/Fractorium/Fractorium.cpp | 13 +++++++++++++ Source/Fractorium/Fractorium.h | 1 + 2 files changed, 14 insertions(+) diff --git a/Source/Fractorium/Fractorium.cpp b/Source/Fractorium/Fractorium.cpp index 5dbef14..18be628 100644 --- a/Source/Fractorium/Fractorium.cpp +++ b/Source/Fractorium/Fractorium.cpp @@ -349,6 +349,19 @@ void Fractorium::resizeEvent(QResizeEvent* e) QMainWindow::resizeEvent(e); } +/// +/// Respond to a show event to ensure Qt updates the native menubar. +/// On first create, Qt can fail to create the native menu bar properly, +/// but telling it that this window has become the focus window forces +/// it to refresh this. +/// The event +void Fractorium::showEvent(QShowEvent *e) +{ + // tell Qt to refresh the native menubar from this widget + emit qGuiApp->focusWindowChanged(windowHandle()); + QMainWindow::showEvent(e); +} + /// /// Stop rendering and block before exiting. /// Called on program exit. diff --git a/Source/Fractorium/Fractorium.h b/Source/Fractorium/Fractorium.h index d311b68..57ef42d 100644 --- a/Source/Fractorium/Fractorium.h +++ b/Source/Fractorium/Fractorium.h @@ -302,6 +302,7 @@ protected: virtual void dragEnterEvent(QDragEnterEvent* e) override; virtual void dragMoveEvent(QDragMoveEvent* e) override; virtual void dropEvent(QDropEvent* e) override; + virtual void showEvent(QShowEvent *e) override; private: void InitMenusUI();