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
qohoswindowutils.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 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
#
include
"qohoswindowutils_p.h"
5
6
#
include
<
QtGui
/
qcolor
.
h
>
7
#
include
<
QtGui
/
qpa
/
qplatformintegration
.
h
>
8
#
include
<
QtGui
/
qscreen
.
h
>
9
#
include
<
QtGui
/
qwindow
.
h
>
10
#
include
<
QtGui
/
private
/
qguiapplication_p
.
h
>
11
#
include
<
QtGui
/
private
/
qohoswindowhints_p
.
h
>
12
#
include
<
QtGui
/
qpa
/
qplatformscreen_p
.
h
>
13
#
include
<
QtGui
/
qpa
/
qplatformwindow_p
.
h
>
14
#
include
<
QtWidgets
/
qwidget
.
h
>
15
16
#
include
<
QtCore
/
qvariant
.
h
>
17
18
#
include
<
optional
>
19
20
QT_BEGIN_NAMESPACE
21
22
/*!
23
\namespace QtHarmonyExtras::Window
24
\inmodule QtHarmonyExtras
25
\brief Applies OpenHarmony-specific hints to a QWindow or QWidget.
26
27
Each hint is recorded on the passed QWindow or QWidget and consumed by the
28
platform plugin. A hint may be set on a QWidget before its window exists; it
29
is carried over to the window once the widget is shown.
30
*/
31
32
namespace
QtHarmonyExtras
{
33
34
namespace
Window {
35
36
/*!
37
Sets or unsets a given \a window as a floating window according to
38
\a showAsFloatWindow. The OpenHarmony window type is fixed at creation, so
39
this has to be called before the window is shown.
40
41
\code
42
auto window = std::make_unique<MainWindow>();
43
QtHarmonyExtras::Window::setShowWindowAsFloatWindowHint(window.get(), true);
44
window->show();
45
\endcode
46
*/
47
void
setShowWindowAsFloatWindowHint
(QWindow *window,
bool
showAsFloatWindow)
48
{
49
window->setProperty(QOhosWindowHints::floatWindowKey, QVariant::fromValue(showAsFloatWindow));
50
}
51
52
/*! \overload */
53
void
setShowWindowAsFloatWindowHint
(QWidget *widget,
bool
showAsFloatWindow)
54
{
55
widget->setProperty(QOhosWindowHints::floatWindowKey, QVariant::fromValue(showAsFloatWindow));
56
}
57
58
/*!
59
Changes the privacy mode of \a window according to \a privacyModeEnabled. In
60
privacy mode the window content cannot be captured or recorded. This requires
61
the ohos.permission.PRIVACY_WINDOW permission to be declared in the
62
application's module.json5.
63
*/
64
void
setWindowPrivacyMode
(QWindow *window,
bool
privacyModeEnabled)
65
{
66
window->setProperty(QOhosWindowHints::privacyModeKey, QVariant::fromValue(privacyModeEnabled));
67
}
68
69
/*!
70
Sets a given \a color as the background color of the \a window inner native
71
layer.
72
*/
73
void
setSurfaceBackgroundColor
(QWindow *window,
const
QColor &color)
74
{
75
window->setProperty(QOhosWindowHints::surfaceBackgroundColorKey, QVariant::fromValue(color));
76
}
77
78
/*!
79
\overload
80
81
Sets a given \a color as the background color of the \a widget inner native
82
layer.
83
*/
84
void
setSurfaceBackgroundColor
(QWidget *widget,
const
QColor &color)
85
{
86
widget->setProperty(QOhosWindowHints::surfaceBackgroundColorKey, QVariant::fromValue(color));
87
}
88
89
/*!
90
Sets the corner \a radius of a \a window. The window has to be a sub or
91
floating window (for example a window with the Qt::Window, Qt::Popup or
92
Qt::Dialog flags, or one marked with setShowWindowAsFloatWindowHint()). The
93
\a radius must not be negative; there is no upper limit, though OHOS visually
94
clamps it to the maximum achievable value.
95
*/
96
void
setWindowCornerRadius
(QWindow *window,
double
radius)
97
{
98
if
(radius < 0.0) {
99
qWarning(
"QtHarmonyExtras::Window::setWindowCornerRadius: radius must not be negative"
);
100
return
;
101
}
102
window->setProperty(QOhosWindowHints::cornerRadiusKey, QVariant::fromValue(radius));
103
}
104
105
/*!
106
\overload
107
108
Sets the corner \a radius of a \a widget. The widget has to be a window on its
109
own (not embedded in a parent widget). The \a radius must not be negative.
110
*/
111
void
setWindowCornerRadius
(QWidget *widget,
double
radius)
112
{
113
if
(radius < 0.0) {
114
qWarning(
"QtHarmonyExtras::Window::setWindowCornerRadius: radius must not be negative"
);
115
return
;
116
}
117
widget->setProperty(QOhosWindowHints::cornerRadiusKey, QVariant::fromValue(radius));
118
}
119
120
/*!
121
Sets or unsets a given \a window to keep the screen on according to
122
\a keepScreenOn.
123
*/
124
void
setWindowKeepScreenOn
(QWindow *window,
bool
keepScreenOn)
125
{
126
window->setProperty(QOhosWindowHints::keepScreenOnKey, QVariant::fromValue(keepScreenOn));
127
}
128
129
/*!
130
\overload
131
132
Sets or unsets a given \a widget to keep the screen on according to
133
\a keepScreenOn.
134
*/
135
void
setWindowKeepScreenOn
(QWidget *widget,
bool
keepScreenOn)
136
{
137
widget->setProperty(QOhosWindowHints::keepScreenOnKey, QVariant::fromValue(keepScreenOn));
138
}
139
140
/*!
141
Enables or disables resizing of \a window by dragging its edges according to
142
\a dragResizable. Takes effect on sub windows and floating windows, but not on
143
the application's main window.
144
*/
145
void
setWindowDragResizable
(QWindow *window,
bool
dragResizable)
146
{
147
window->setProperty(QOhosWindowHints::dragResizableKey, QVariant::fromValue(dragResizable));
148
}
149
150
/*!
151
\overload
152
153
Enables or disables resizing of \a widget by dragging its edges according to
154
\a dragResizable. The widget has to be a window on its own (not embedded in a
155
parent widget). Takes effect on sub windows and floating windows, but not on
156
the application's main window.
157
*/
158
void
setWindowDragResizable
(QWidget *widget,
bool
dragResizable)
159
{
160
widget->setProperty(QOhosWindowHints::dragResizableKey, QVariant::fromValue(dragResizable));
161
}
162
163
/*!
164
Sets whether the application's main window restores its last geometry on
165
startup according to \a hint. WindowGeometryPersistenceHint::FollowSystemSetting
166
defers to the system default. This has to be called before the main window is
167
shown.
168
*/
169
void
setMainWindowGeometryPersistenceHint
(
WindowGeometryPersistenceHint
hint)
170
{
171
std
::optional<
bool
> enabled;
172
switch
(hint) {
173
case
WindowGeometryPersistenceHint
::
Disabled
:
174
enabled =
false
;
175
break
;
176
case
WindowGeometryPersistenceHint
::
Enabled
:
177
enabled =
true
;
178
break
;
179
case
WindowGeometryPersistenceHint
::
FollowSystemSetting
:
180
break
;
181
}
182
183
using
QOhosIntegration = QNativeInterface::Private::QOhosIntegration;
184
auto
*integration = QGuiApplicationPrivate::platformIntegration();
185
integration->call<&QOhosIntegration::setMainWindowGeometryPersistenceEnabled>(enabled);
186
}
187
188
}
189
190
std
::
optional
<
qint64
>
tryGetNativeWindowId
(QWindow *window)
191
{
192
auto
*ohosWindow = window->nativeInterface<QNativeInterface::Private::QOhosWindow>();
193
if
(!ohosWindow)
194
return
{};
195
196
const
std
::optional<
double
> optWindowId = ohosWindow->windowId();
197
if
(!optWindowId)
198
return
{};
199
200
qint64 windowId = 0;
201
if
(!convertDoubleTo(*optWindowId, &windowId)) {
202
qWarning(
"tryGetNativeWindowId: window id %g out of qint64 range"
, *optWindowId);
203
return
{};
204
}
205
206
return
windowId;
207
}
208
209
std
::
optional
<
qint64
>
tryGetScreenDisplayId
(QScreen *screen)
210
{
211
auto
*ohosScreen = screen->nativeInterface<QNativeInterface::Private::QOhosScreen>();
212
if
(!ohosScreen)
213
return
{};
214
215
const
double
ohosDisplayId = ohosScreen->displayId();
216
qint64 displayId = 0;
217
if
(!convertDoubleTo(ohosDisplayId, &displayId)) {
218
qWarning(
"tryGetScreenDisplayId: display id %g out of qint64 range"
, ohosDisplayId);
219
return
{};
220
}
221
222
return
displayId;
223
}
224
225
}
226
227
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtHarmonyExtras::Window::setWindowKeepScreenOn
void setWindowKeepScreenOn(QWindow *window, bool keepScreenOn)
Sets or unsets a given window to keep the screen on according to keepScreenOn.
Definition
qohoswindowutils.cpp:124
QtHarmonyExtras::Window::setWindowCornerRadius
void setWindowCornerRadius(QWindow *window, double radius)
Sets the corner radius of a window.
Definition
qohoswindowutils.cpp:96
QtHarmonyExtras::Window::setShowWindowAsFloatWindowHint
void setShowWindowAsFloatWindowHint(QWindow *window, bool showAsFloatWindow)
Sets or unsets a given window as a floating window according to showAsFloatWindow.
Definition
qohoswindowutils.cpp:47
QtHarmonyExtras::Window::setSurfaceBackgroundColor
void setSurfaceBackgroundColor(QWindow *window, const QColor &color)
Sets a given color as the background color of the window inner native layer.
Definition
qohoswindowutils.cpp:73
QtHarmonyExtras::Window::WindowGeometryPersistenceHint
WindowGeometryPersistenceHint
Definition
qohoswindowutils_p.h:37
QtHarmonyExtras::Window::WindowGeometryPersistenceHint::Enabled
@ Enabled
Definition
qohoswindowutils_p.h:39
QtHarmonyExtras::Window::WindowGeometryPersistenceHint::FollowSystemSetting
@ FollowSystemSetting
Definition
qohoswindowutils_p.h:40
QtHarmonyExtras::Window::WindowGeometryPersistenceHint::Disabled
@ Disabled
Definition
qohoswindowutils_p.h:38
QtHarmonyExtras::Window::setWindowDragResizable
void setWindowDragResizable(QWindow *window, bool dragResizable)
Enables or disables resizing of window by dragging its edges according to dragResizable.
Definition
qohoswindowutils.cpp:145
QtHarmonyExtras::Window::setWindowPrivacyMode
void setWindowPrivacyMode(QWindow *window, bool privacyModeEnabled)
Changes the privacy mode of window according to privacyModeEnabled.
Definition
qohoswindowutils.cpp:64
QtHarmonyExtras::Window::setMainWindowGeometryPersistenceHint
void setMainWindowGeometryPersistenceHint(WindowGeometryPersistenceHint hint)
Sets whether the application's main window restores its last geometry on startup according to hint.
Definition
qohoswindowutils.cpp:169
QtHarmonyExtras
Definition
qohosabilitycontext.cpp:36
QtHarmonyExtras::tryGetNativeWindowId
std::optional< qint64 > tryGetNativeWindowId(QWindow *window)
Definition
qohoswindowutils.cpp:190
QtHarmonyExtras::tryGetScreenDisplayId
std::optional< qint64 > tryGetScreenDisplayId(QScreen *screen)
Definition
qohoswindowutils.cpp:209
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtbase
src
plugins
platforms
ohos
extras
qohoswindowutils.cpp
Generated on
for Qt by
1.16.1