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
qwindow.h
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#ifndef QWINDOW_H
6#define QWINDOW_H
7
8#include <QtGui/qtguiglobal.h>
9#include <QtCore/QObject>
10#include <QtCore/QEvent>
11#include <QtCore/QMargins>
12#include <QtCore/QRect>
13
14#include <QtCore/qnamespace.h>
15#include <QtCore/qnativeinterface.h>
16
17#include <QtGui/qsurface.h>
18#include <QtGui/qsurfaceformat.h>
19#include <QtGui/qwindowdefs.h>
20
21#include <QtGui/qicon.h>
22
23#ifndef QT_NO_CURSOR
24#include <QtGui/qcursor.h>
25#endif
26
28
29
30class QWindowPrivate;
31
32class QExposeEvent;
33class QPaintEvent;
34class QFocusEvent;
35class QMoveEvent;
36class QResizeEvent;
37class QShowEvent;
38class QHideEvent;
39class QCloseEvent;
40class QKeyEvent;
41class QMouseEvent;
42#if QT_CONFIG(wheelevent)
43class QWheelEvent;
44#endif
45class QTouchEvent;
46#if QT_CONFIG(tabletevent)
47class QTabletEvent;
48#endif
49
50class QPlatformSurface;
51class QPlatformWindow;
52class QBackingStore;
53class QScreen;
54class QAccessibleInterface;
55class QWindowContainer;
56#ifndef QT_NO_DEBUG_STREAM
57class QDebug;
58#endif
59#if QT_CONFIG(vulkan) || defined(Q_QDOC)
60class QVulkanInstance;
61#endif
62
63class Q_GUI_EXPORT QWindow : public QObject, public QSurface
64{
65 Q_OBJECT
66 Q_DECLARE_PRIVATE(QWindow)
67
68 // All properties which are declared here are inherited by QQuickWindow and therefore available in QML.
69 // So please think carefully about what it does to the QML namespace if you add any new ones,
70 // particularly the possible meanings these names might have in any specializations of Window.
71 // For example "state" (meaning windowState) is not a good property to declare, because it has
72 // a different meaning in QQuickItem, and users will tend to assume it is the same for Window.
73
74 // Any new properties which you add here MUST be versioned and MUST be documented both as
75 // C++ properties in qwindow.cpp AND as QML properties in qquickwindow.cpp.
76 // https://doc.qt.io/qt/qtqml-cppintegration-definetypes.html#type-revisions-and-versions
77
78 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY windowTitleChanged)
79 Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged)
80 Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFlags NOTIFY flagsChanged)
81 Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
82 Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
83 Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
84 Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
85 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged)
86 Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight
87 NOTIFY minimumHeightChanged)
88 Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged)
89 Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight
90 NOTIFY maximumHeightChanged)
91 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged VIRTUAL)
92 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged REVISION(2, 1))
93 Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged VIRTUAL REVISION(2, 1))
94 Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation
95 WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
96 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged REVISION(2, 1))
97#ifdef Q_QDOC
98 Q_PROPERTY(QWindow* transientParent READ transientParent WRITE setTransientParent NOTIFY transientParentChanged)
99#else
100 Q_PRIVATE_PROPERTY(QWindow::d_func(), QWindow* transientParent MEMBER transientParent
101 WRITE setTransientParent NOTIFY transientParentChanged REVISION(2, 13))
102#endif
103
104public:
105 enum Visibility {
106 Hidden = 0,
107 AutomaticVisibility,
108 Windowed,
109 Minimized,
110 Maximized,
111 FullScreen
112 };
113 Q_ENUM(Visibility)
114
115 enum AncestorMode {
116 ExcludeTransients,
117 IncludeTransients
118 };
119 Q_ENUM(AncestorMode)
120
121 explicit QWindow(QScreen *screen = nullptr);
122 explicit QWindow(QWindow *parent);
123 ~QWindow();
124
125 void setSurfaceType(SurfaceType surfaceType);
126 SurfaceType surfaceType() const override;
127
128 bool isVisible() const;
129
130 Visibility visibility() const;
131 void setVisibility(Visibility v);
132
133 void create();
134
135 WId winId() const;
136
137 QWindow *parent(AncestorMode mode = ExcludeTransients) const;
138 void setParent(QWindow *parent);
139
140 bool isTopLevel() const;
141
142 bool isModal() const;
143 Qt::WindowModality modality() const;
144 void setModality(Qt::WindowModality modality);
145
146 void setFormat(const QSurfaceFormat &format);
147 QSurfaceFormat format() const override;
148 QSurfaceFormat requestedFormat() const;
149
150 void setFlags(Qt::WindowFlags flags);
151 Qt::WindowFlags flags() const;
152 void setFlag(Qt::WindowType, bool on = true);
153 Qt::WindowType type() const;
154
155 QString title() const;
156
157 void setOpacity(qreal level);
158 qreal opacity() const;
159
160 void setMask(const QRegion &region);
161 QRegion mask() const;
162
163 bool isActive() const;
164
165 void reportContentOrientationChange(Qt::ScreenOrientation orientation);
166 Qt::ScreenOrientation contentOrientation() const;
167
168 qreal devicePixelRatio() const;
169
170 Qt::WindowState windowState() const;
171 Qt::WindowStates windowStates() const;
172 void setWindowState(Qt::WindowState state);
173 void setWindowStates(Qt::WindowStates states);
174
175 void setTransientParent(QWindow *parent);
176 QWindow *transientParent() const;
177
178 bool isAncestorOf(const QWindow *child, AncestorMode mode = IncludeTransients) const;
179
180 bool isExposed() const;
181
182 inline int minimumWidth() const { return minimumSize().width(); }
183 inline int minimumHeight() const { return minimumSize().height(); }
184 inline int maximumWidth() const { return maximumSize().width(); }
185 inline int maximumHeight() const { return maximumSize().height(); }
186
187 QSize minimumSize() const;
188 QSize maximumSize() const;
189 QSize baseSize() const;
190 QSize sizeIncrement() const;
191
192 void setMinimumSize(const QSize &size);
193 void setMaximumSize(const QSize &size);
194 void setBaseSize(const QSize &size);
195 void setSizeIncrement(const QSize &size);
196
197 QRect geometry() const;
198
199 QMargins frameMargins() const;
200 QRect frameGeometry() const;
201
202 QPoint framePosition() const;
203 void setFramePosition(const QPoint &point);
204 void setFramePosition(int x, int y)
205 { setFramePosition(QPoint(x, y)); }
206
207 QMargins safeAreaMargins() const;
208
209 inline int width() const { return geometry().width(); }
210 inline int height() const { return geometry().height(); }
211 inline int x() const { return geometry().x(); }
212 inline int y() const { return geometry().y(); }
213
214 QSize size() const override { return geometry().size(); }
215 inline QPoint position() const { return geometry().topLeft(); }
216
217 void setPosition(const QPoint &pt);
218 void setPosition(int posx, int posy);
219
220 void resize(const QSize &newSize);
221 void resize(int w, int h);
222
223 void setFilePath(const QString &filePath);
224 QString filePath() const;
225
226 void setIcon(const QIcon &icon);
227 QIcon icon() const;
228
229 void destroy();
230
231 QPlatformWindow *handle() const;
232
233 bool setKeyboardGrabEnabled(bool grab);
234 bool setMouseGrabEnabled(bool grab);
235
236 QScreen *screen() const;
237 void setScreen(QScreen *screen);
238
239 virtual QAccessibleInterface *accessibleRoot() const;
240 virtual QObject *focusObject() const;
241
242 QPointF mapToGlobal(const QPointF &pos) const;
243 QPointF mapFromGlobal(const QPointF &pos) const;
244 QPoint mapToGlobal(const QPoint &pos) const;
245 QPoint mapFromGlobal(const QPoint &pos) const;
246
247#ifndef QT_NO_CURSOR
248 QCursor cursor() const;
249 void setCursor(const QCursor &);
250 void unsetCursor();
251#endif
252
253 static QWindow *fromWinId(WId id);
254
255#if QT_CONFIG(vulkan) || defined(Q_QDOC)
256 void setVulkanInstance(QVulkanInstance *instance);
257 QVulkanInstance *vulkanInstance() const;
258#endif
259
260 QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QWindow)
261
262public Q_SLOTS:
263 Q_REVISION(2, 1) void requestActivate();
264
265 void setVisible(bool visible);
266
267 void show();
268 void hide();
269
270 void showMinimized();
271 void showMaximized();
272 void showFullScreen();
273 void showNormal();
274
275 bool close();
276 void raise();
277 void lower();
278 bool startSystemResize(Qt::Edges edges);
279 bool startSystemMove();
280
281 void setTitle(const QString &);
282
283 void setX(int arg);
284 void setY(int arg);
285 void setWidth(int arg);
286 void setHeight(int arg);
287 void setGeometry(int posx, int posy, int w, int h);
288 void setGeometry(const QRect &rect);
289
290 void setMinimumWidth(int w);
291 void setMinimumHeight(int h);
292 void setMaximumWidth(int w);
293 void setMaximumHeight(int h);
295 Q_REVISION(2, 1) void alert(int msec);
296
297 Q_REVISION(2, 3) void requestUpdate();
299Q_SIGNALS:
300 void screenChanged(QScreen *screen);
301 void modalityChanged(Qt::WindowModality modality);
302 Q_REVISION(6, 10) void flagsChanged(Qt::WindowFlags flags);
303 void windowStateChanged(Qt::WindowState windowState);
304 Q_REVISION(2, 2) void windowTitleChanged(const QString &title);
305
306 void xChanged(int arg);
307 void yChanged(int arg);
308
309 void widthChanged(int arg);
310 void heightChanged(int arg);
312 void minimumWidthChanged(int arg);
313 void minimumHeightChanged(int arg);
314 void maximumWidthChanged(int arg);
315 void maximumHeightChanged(int arg);
317 Q_REVISION(6, 9) void safeAreaMarginsChanged(QMargins arg);
319 void visibleChanged(bool arg);
320 Q_REVISION(2, 1) void visibilityChanged(QWindow::Visibility visibility);
321 Q_REVISION(2, 1) void activeChanged();
322 void contentOrientationChanged(Qt::ScreenOrientation orientation);
324 void focusObjectChanged(QObject *object);
326 Q_REVISION(2, 1) void opacityChanged(qreal opacity);
327
328 Q_REVISION(2, 13) void transientParentChanged(QWindow *transientParent);
329
330protected:
331 virtual void exposeEvent(QExposeEvent *);
332 virtual void resizeEvent(QResizeEvent *);
333 virtual void paintEvent(QPaintEvent *);
334 virtual void moveEvent(QMoveEvent *);
335 virtual void focusInEvent(QFocusEvent *);
336 virtual void focusOutEvent(QFocusEvent *);
337
338 virtual void showEvent(QShowEvent *);
339 virtual void hideEvent(QHideEvent *);
340 virtual void closeEvent(QCloseEvent *);
341
342 virtual bool event(QEvent *) override;
343 virtual void keyPressEvent(QKeyEvent *);
344 virtual void keyReleaseEvent(QKeyEvent *);
345 virtual void mousePressEvent(QMouseEvent *);
346 virtual void mouseReleaseEvent(QMouseEvent *);
347 virtual void mouseDoubleClickEvent(QMouseEvent *);
348 virtual void mouseMoveEvent(QMouseEvent *);
349#if QT_CONFIG(wheelevent)
350 virtual void wheelEvent(QWheelEvent *);
351#endif
352 virtual void touchEvent(QTouchEvent *);
353#if QT_CONFIG(tabletevent)
354 virtual void tabletEvent(QTabletEvent *);
355#endif
356 virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result);
357
358 QWindow(QWindowPrivate &dd, QWindow *parent);
359
360private:
361 Q_PRIVATE_SLOT(d_func(), void _q_clearAlert())
362 QPlatformSurface *surfaceHandle() const override;
364 Q_DISABLE_COPY(QWindow)
366 friend class QGuiApplication;
367 friend class QGuiApplicationPrivate;
368 friend class QWindowContainer;
369 friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window);
370};
371
372#ifndef Q_QDOC
373// should these be seen by clang-qdoc?
374template <> inline QWindow *qobject_cast<QWindow*>(QObject *o)
375{
376 if (!o || !o->isWindowType()) return nullptr;
377 return static_cast<QWindow*>(o);
378}
379template <> inline const QWindow *qobject_cast<const QWindow*>(const QObject *o)
380{
381 if (!o || !o->isWindowType()) return nullptr;
382 return static_cast<const QWindow*>(o);
383}
384#endif // !Q_QDOC
385
386#ifndef QT_NO_DEBUG_STREAM
387Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindow *);
388#endif
389
390QT_END_NAMESPACE
391
392#endif // QWINDOW_H
\inmodule QtGui
The QPlatformSurface class provides an abstraction for a surface.
\inmodule QtGui
Definition qwindow.h:64
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582