Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmenu_mac.mm
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
import
<
Foundation
/
Foundation
.
h
>
5
#
import
<
AppKit
/
AppKit
.
h
>
6
7
#
include
<
qtwidgetsglobal
.
h
>
8
9
QT_USE_NAMESPACE
10
11
#
include
"qmenu.h"
12
#
if
QT_CONFIG
(
menubar
)
13
#
include
"qmenubar.h"
14
#
include
"qmenubar_p.h"
15
#
endif
16
17
#
include
<
QtCore
/
QDebug
>
18
#
include
<
QtGui
/
QGuiApplication
>
19
#
include
<
QtGui
/
QWindow
>
20
#
include
<
qpa
/
qplatformnativeinterface
.
h
>
21
#
include
<
qpa
/
qplatformmenu_p
.
h
>
22
23
using
namespace
QNativeInterface::Private;
24
25
QT_BEGIN_NAMESPACE
26
27
#
if
QT_CONFIG
(
menu
)
28
29
/*!
30
\fn NSMenu *QMenu::toNSMenu()
31
\since 5.2
32
33
Returns the native NSMenu for this menu. Available on \macos only.
34
35
\note Qt sets the delegate on the native menu. If you need to set your own
36
delegate, make sure you save the original one and forward any calls to it.
37
*/
38
NSMenu
*
QMenu
::
toNSMenu
()
39
{
40
Q_D
(
QMenu
);
41
if
(
auto
*
cocoaPlatformMenu
=
dynamic_cast
<
QCocoaMenu
*>(
d
->
createPlatformMenu
()))
42
return
cocoaPlatformMenu
->
nsMenu
();
43
44
return
nil
;
45
}
46
47
48
/*!
49
\fn void QMenu::setAsDockMenu()
50
\since 5.2
51
52
Set this menu to be the dock menu available by option-clicking
53
on the application dock icon. Available on \macos only.
54
*/
55
void
QMenu
::
setAsDockMenu
()
56
{
57
Q_D
(
QMenu
);
58
if
(
auto
*
cocoaPlatformMenu
=
dynamic_cast
<
QCocoaMenu
*>(
d
->
createPlatformMenu
()))
59
cocoaPlatformMenu
->
setAsDockMenu
();
60
}
61
62
void
QMenuPrivate
::
moveWidgetToPlatformItem
(
QWidget
*
widget
,
QPlatformMenuItem
*
item
)
63
{
64
// Hide the widget before we mess with it
65
widget
->
hide
();
66
67
// Move out of QMenu, since this widget will live in the native menu item
68
widget
->
setParent
(
nullptr
);
69
70
// Make sure the widget doesn't prevent quitting the application,
71
// just because it's a parent-less (top level) window.
72
widget
->
setAttribute
(
Qt
::
WA_QuitOnClose
,
false
);
73
74
// And that it blends nicely with the native menu background
75
widget
->
setAttribute
(
Qt
::
WA_TranslucentBackground
);
76
77
// Trigger creation of the backing QWindow, the platform window, and its
78
// underlying NSView and NSWindow. At this point the widget is still hidden,
79
// so the corresponding NSWindow that is created is not shown.
80
widget
->
setAttribute
(
Qt
::
WA_NativeWindow
);
81
QWindow
*
widgetWindow
=
widget
->
windowHandle
();
82
widgetWindow
->
create
();
83
84
// Inform the window that it's actually a sub-window. This
85
// ensures that we dispose of the NSWindow when the widget is
86
// finally shown. We need to do this on a QWindow level, as
87
// QWidget will ignore the flag if there is no parentWidget().
88
// And we need to do it after creating the platform window, as
89
// QWidget will overwrite the window flags during creation.
90
widgetWindow
->
setFlag
(
Qt
::
SubWindow
);
91
92
// Finally, we can associate the underlying NSView with the menu item,
93
// and show it. This will dispose of the created NSWindow, due to
94
// the Qt::SubWindow flag above. The widget will not actually be
95
// visible until it's re-parented into the NSMenu hierarchy.
96
item
->
setNativeContents
(
WId
(
widgetWindow
->
winId
()));
97
widget
->
show
();
98
}
99
100
#
endif
// QT_CONFIG(menu)
101
102
#
if
QT_CONFIG
(
menubar
)
103
104
/*!
105
\fn NSMenu *QMenuBar::toNSMenu()
106
\since 5.2
107
108
Returns the native NSMenu for this menu bar. Available on \macos only.
109
110
\note Qt may set the delegate on the native menu bar. If you need to set your
111
own delegate, make sure you save the original one and forward any calls to it.
112
*/
113
NSMenu
*
QMenuBar
::
toNSMenu
()
114
{
115
if
(
auto
*
cocoaMenuBar
=
dynamic_cast
<
QCocoaMenuBar
*>(
platformMenuBar
()))
116
return
cocoaMenuBar
->
nsMenu
();
117
118
return
nil
;
119
}
120
#
endif
// QT_CONFIG(menubar)
121
122
QT_END_NAMESPACE
QSqlRelationalDelegate
\inmodule QtSql
qtbase
src
widgets
widgets
qmenu_mac.mm
Generated on Mon Mar 10 2025 00:47:22 for Qt by
1.13.2