QShortcut: Try harder to find a widget for parentless menubars
Add QPlatformMenuBar::parentWindow(). Since we call handleReparent() every so often, it's reasonable to be able to get its value back. While this parent window won't give us much information from the point of view of the actual QWidget parent for the menubar, the main reason we will need this is to check for modality blockage. Indeed, QApplicationPrivate::tryModalHelper() only cares about the widget's window since modality blockage is decided at the window level. Change-Id: Ie79f483424b01e430bc9168ba82489e30d15aec6 Task-number: QTBUG-67938 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
93cf1cf2e5
commit
8447f5f006
@ -158,6 +158,7 @@ public:
|
||||
virtual void removeMenu(QPlatformMenu *menu) = 0;
|
||||
virtual void syncMenu(QPlatformMenu *menuItem) = 0;
|
||||
virtual void handleReparent(QWindow *newParentWindow) = 0;
|
||||
virtual QWindow *parentWindow() const { return nullptr; }
|
||||
|
||||
virtual QPlatformMenu *menuForTag(quintptr tag) const = 0;
|
||||
virtual QPlatformMenu *createMenu() const;
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
void removeMenu(QPlatformMenu *menu) override;
|
||||
void syncMenu(QPlatformMenu *menuItem) override;
|
||||
void handleReparent(QWindow *newParentWindow) override;
|
||||
QWindow *parentWindow() const override;
|
||||
QPlatformMenu *menuForTag(quintptr tag) const override;
|
||||
|
||||
inline NSMenu *nsMenu() const
|
||||
|
@ -241,6 +241,12 @@ void QCocoaMenuBar::handleReparent(QWindow *newParentWindow)
|
||||
updateMenuBarImmediately();
|
||||
}
|
||||
|
||||
QWindow *QCocoaMenuBar::parentWindow() const
|
||||
{
|
||||
return m_window ? m_window->window() : nullptr;
|
||||
}
|
||||
|
||||
|
||||
QCocoaWindow *QCocoaMenuBar::findWindowForMenubar()
|
||||
{
|
||||
if (qApp->focusWindow())
|
||||
|
@ -149,8 +149,16 @@ static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidge
|
||||
bool visible = w->isVisible();
|
||||
#if QT_CONFIG(menubar)
|
||||
if (QMenuBar *menuBar = qobject_cast<QMenuBar *>(w)) {
|
||||
if (menuBar->isNativeMenuBar())
|
||||
visible = true;
|
||||
if (auto *pmb = menuBar->platformMenuBar()) {
|
||||
if (menuBar->parentWidget()) {
|
||||
visible = true;
|
||||
} else {
|
||||
if (auto *ww = qobject_cast<QWidgetWindow *>(pmb->parentWindow()))
|
||||
w = ww->widget(); // Good enough since we only care about the window
|
||||
else
|
||||
return false; // This is not a QWidget window. We won't deliver
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user