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