Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QWINDOW_H
5#define QWINDOW_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/QObject>
9#include <QtCore/QEvent>
10#include <QtCore/QMargins>
11#include <QtCore/QRect>
12
13#include <QtCore/qnamespace.h>
14#include <QtCore/qnativeinterface.h>
15
16#include <QtGui/qsurface.h>
17#include <QtGui/qsurfaceformat.h>
18#include <QtGui/qwindowdefs.h>
19
20#include <QtGui/qicon.h>
21
22#ifndef QT_NO_CURSOR
23#include <QtGui/qcursor.h>
24#endif
25
27
28
29class QWindowPrivate;
30
31class QExposeEvent;
32class QPaintEvent;
33class QFocusEvent;
34class QMoveEvent;
35class QResizeEvent;
36class QShowEvent;
37class QHideEvent;
38class QCloseEvent;
39class QKeyEvent;
40class QMouseEvent;
41#if QT_CONFIG(wheelevent)
42class QWheelEvent;
43#endif
44class QTouchEvent;
45#if QT_CONFIG(tabletevent)
46class QTabletEvent;
47#endif
48
50class QPlatformWindow;
51class QBackingStore;
52class QScreen;
53class QAccessibleInterface;
55#ifndef QT_NO_DEBUG_STREAM
56class QDebug;
57#endif
58#if QT_CONFIG(vulkan) || defined(Q_QDOC)
59class QVulkanInstance;
60#endif
61
62class Q_GUI_EXPORT QWindow : public QObject, public QSurface
63{
65 Q_DECLARE_PRIVATE(QWindow)
66
67 // All properties which are declared here are inherited by QQuickWindow and therefore available in QML.
68 // So please think carefully about what it does to the QML namespace if you add any new ones,
69 // particularly the possible meanings these names might have in any specializations of Window.
70 // For example "state" (meaning windowState) is not a good property to declare, because it has
71 // a different meaning in QQuickItem, and users will tend to assume it is the same for Window.
72
73 // Any new properties which you add here MUST be versioned and MUST be documented both as
74 // C++ properties in qwindow.cpp AND as QML properties in qquickwindow.cpp.
75 // https://doc.qt.io/qt/qtqml-cppintegration-definetypes.html#type-revisions-and-versions
76
77 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY windowTitleChanged)
78 Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged)
79 Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFlags)
80 Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
81 Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
82 Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
83 Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
84 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged)
85 Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight
86 NOTIFY minimumHeightChanged)
87 Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged)
88 Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight
89 NOTIFY maximumHeightChanged)
90 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
91 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged REVISION(2, 1))
92 Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged
93 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;
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
205 inline int width() const { return geometry().width(); }
206 inline int height() const { return geometry().height(); }
207 inline int x() const { return geometry().x(); }
208 inline int y() const { return geometry().y(); }
209
210 QSize size() const override { return geometry().size(); }
211 inline QPoint position() const { return geometry().topLeft(); }
212
213 void setPosition(const QPoint &pt);
214 void setPosition(int posx, int posy);
215
216 void resize(const QSize &newSize);
217 void resize(int w, int h);
218
219 void setFilePath(const QString &filePath);
220 QString filePath() const;
221
222 void setIcon(const QIcon &icon);
223 QIcon icon() const;
224
225 void destroy();
226
227 QPlatformWindow *handle() const;
228
229 bool setKeyboardGrabEnabled(bool grab);
230 bool setMouseGrabEnabled(bool grab);
231
232 QScreen *screen() const;
233 void setScreen(QScreen *screen);
234
235 virtual QAccessibleInterface *accessibleRoot() const;
236 virtual QObject *focusObject() const;
237
238 QPointF mapToGlobal(const QPointF &pos) const;
239 QPointF mapFromGlobal(const QPointF &pos) const;
240 QPoint mapToGlobal(const QPoint &pos) const;
241 QPoint mapFromGlobal(const QPoint &pos) const;
242
243#ifndef QT_NO_CURSOR
244 QCursor cursor() const;
245 void setCursor(const QCursor &);
246 void unsetCursor();
247#endif
248
249 static QWindow *fromWinId(WId id);
250
251#if QT_CONFIG(vulkan) || defined(Q_QDOC)
252 void setVulkanInstance(QVulkanInstance *instance);
253 QVulkanInstance *vulkanInstance() const;
254#endif
255
257
258public Q_SLOTS:
259 Q_REVISION(2, 1) void requestActivate();
260
261 void setVisible(bool visible);
262
263 void show();
264 void hide();
265
266 void showMinimized();
267 void showMaximized();
268 void showFullScreen();
269 void showNormal();
270
271 bool close();
272 void raise();
273 void lower();
274 bool startSystemResize(Qt::Edges edges);
275 bool startSystemMove();
276
277 void setTitle(const QString &);
278
279 void setX(int arg);
280 void setY(int arg);
281 void setWidth(int arg);
282 void setHeight(int arg);
283 void setGeometry(int posx, int posy, int w, int h);
284 void setGeometry(const QRect &rect);
285
286 void setMinimumWidth(int w);
287 void setMinimumHeight(int h);
288 void setMaximumWidth(int w);
289 void setMaximumHeight(int h);
290
291 Q_REVISION(2, 1) void alert(int msec);
292
293 Q_REVISION(2, 3) void requestUpdate();
294
296 void screenChanged(QScreen *screen);
297 void modalityChanged(Qt::WindowModality modality);
298 void windowStateChanged(Qt::WindowState windowState);
299 Q_REVISION(2, 2) void windowTitleChanged(const QString &title);
300
301 void xChanged(int arg);
302 void yChanged(int arg);
303
304 void widthChanged(int arg);
305 void heightChanged(int arg);
306
307 void minimumWidthChanged(int arg);
308 void minimumHeightChanged(int arg);
309 void maximumWidthChanged(int arg);
310 void maximumHeightChanged(int arg);
311
312 void visibleChanged(bool arg);
313 Q_REVISION(2, 1) void visibilityChanged(QWindow::Visibility visibility);
314 Q_REVISION(2, 1) void activeChanged();
315 void contentOrientationChanged(Qt::ScreenOrientation orientation);
316
317 void focusObjectChanged(QObject *object);
318
319 Q_REVISION(2, 1) void opacityChanged(qreal opacity);
320
321 Q_REVISION(2, 13) void transientParentChanged(QWindow *transientParent);
322
323protected:
324 virtual void exposeEvent(QExposeEvent *);
325 virtual void resizeEvent(QResizeEvent *);
326 virtual void paintEvent(QPaintEvent *);
327 virtual void moveEvent(QMoveEvent *);
328 virtual void focusInEvent(QFocusEvent *);
329 virtual void focusOutEvent(QFocusEvent *);
330
331 virtual void showEvent(QShowEvent *);
332 virtual void hideEvent(QHideEvent *);
333 virtual void closeEvent(QCloseEvent *);
334
335 virtual bool event(QEvent *) override;
336 virtual void keyPressEvent(QKeyEvent *);
337 virtual void keyReleaseEvent(QKeyEvent *);
338 virtual void mousePressEvent(QMouseEvent *);
339 virtual void mouseReleaseEvent(QMouseEvent *);
340 virtual void mouseDoubleClickEvent(QMouseEvent *);
341 virtual void mouseMoveEvent(QMouseEvent *);
342#if QT_CONFIG(wheelevent)
343 virtual void wheelEvent(QWheelEvent *);
344#endif
345 virtual void touchEvent(QTouchEvent *);
346#if QT_CONFIG(tabletevent)
347 virtual void tabletEvent(QTabletEvent *);
348#endif
349 virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result);
350
351 QWindow(QWindowPrivate &dd, QWindow *parent);
352
353private:
354 Q_PRIVATE_SLOT(d_func(), void _q_clearAlert())
355 QPlatformSurface *surfaceHandle() const override;
356
357 Q_DISABLE_COPY(QWindow)
358
359 friend class QGuiApplication;
361 friend class QWindowContainer;
362 friend Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window);
363};
364
365#ifndef Q_QDOC
366// should these be seen by clang-qdoc?
368{
369 if (!o || !o->isWindowType()) return nullptr;
370 return static_cast<QWindow*>(o);
371}
372template <> inline const QWindow *qobject_cast<const QWindow*>(const QObject *o)
373{
374 if (!o || !o->isWindowType()) return nullptr;
375 return static_cast<const QWindow*>(o);
376}
377#endif // !Q_QDOC
378
379#ifndef QT_NO_DEBUG_STREAM
380Q_GUI_EXPORT QDebug operator<<(QDebug, const QWindow *);
381#endif
382
384
385#endif // QWINDOW_H
bool isActive
The QBackingStore class provides a drawing area for QWindow.
\inmodule QtCore
Definition qbytearray.h:57
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:45
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition qevent.h:515
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\macro qGuiApp
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
The QKeyEvent class describes a key event.
Definition qevent.h:424
\inmodule QtCore
Definition qmargins.h:24
\inmodule QtGui
Definition qevent.h:196
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:502
\inmodule QtCore
Definition qobject.h:103
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPlatformSurface class provides an abstraction for a surface.
The QPlatformWindow class provides an abstraction for top-level windows.
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
\inmodule QtGui
Definition qsurface.h:21
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
The QVulkanInstance class represents a native Vulkan instance, enabling Vulkan rendering onto a QSurf...
\inmodule QtGui
Definition qwindow.h:63
Q_PRIVATE_SLOT(d_func(), void _q_clearAlert()) QPlatformSurface *surfaceHandle() const override
QSize size() const override
Returns the size of the window excluding any window frame.
Definition qwindow.h:210
Q_REVISION(2, 1) void requestActivate()
widget setFormat(format)
a resize(100000)
QCursor cursor
rect
[4]
else opt state
[0]
Combined button and popup list for selecting options.
Definition qcompare.h:63
WindowState
Definition qnamespace.h:251
WindowModality
ScreenOrientation
Definition qnamespace.h:271
WindowType
Definition qnamespace.h:205
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
static void unsetCursor(QWindow *w)
#define QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(T)
n void setPosition(void) \n\
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
GLenum type
GLbitfield flags
GLuint GLsizei const GLchar * message
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLint y
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
GLuint64EXT * result
[6]
GLuint * states
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
SSL_CTX int void * arg
QScreen * screen
[1]
Definition main.cpp:29
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_SLOTS
#define Q_SIGNALS
#define Q_PRIVATE_PROPERTY(d, text)
double qreal
Definition qtypes.h:187
ptrdiff_t qintptr
Definition qtypes.h:166
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition qwindow.cpp:2950
QWindow * qobject_cast< QWindow * >(QObject *o)
Definition qwindow.h:367
const QWindow * qobject_cast< const QWindow * >(const QObject *o)
Definition qwindow.h:372
static QRect frameGeometry(HWND hwnd, bool topLevel)
view show()
[18] //! [19]
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QString title
[35]
p setX(p.x()+1)
item setCursor(Qt::IBeamCursor)
[1]
edit hide()
edit isVisible()
myAction setIcon(SomeIcon)
QLayoutItem * child
[0]
w setWindowState(w->windowState() ^ Qt::WindowFullScreen)
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
g setTitle("&User information")
[0]
file setParent(multiPart)
view create()