QWindow ClassThe QWindow class represents a window in the underlying windowing system. More... #include <QWindow> Inherits: QObject and QSurface. Inherited by: QGLMockView, QGLView, and QQuickCanvas. This class was introduced in Qt 5.0. Public Types
Properties
Public Functions
Reimplemented Public Functions
Public Slots
Signals
Protected Functions
Reimplemented Protected Functions
Additional Inherited Members
Detailed DescriptionThe QWindow class represents a window in the underlying windowing system. A window that is supplied a parent becomes a native child window of their parent window. Resource managementWindows can potentially use a lot of memory. A usual measurement is width times height times color depth. A window might also include multiple buffers to support double and triple buffering, as well as depth and stencil buffers. To release a window's memory resources, the destroy() function. Window and content orientationQWindow has reportContentOrientationChange() and requestWindowOrientation() that can be used to specify the layout of the window contents in relation to the screen. The window orientation determines the actual buffer layout of the window, and the windowing system uses this value to rotate the window before it ends up on the display, and to ensure that input coordinates are in the correct coordinate space relative to the application. On the other hand, the content orientation is simply a hint to the windowing system about which orientation the window contents are in. It's useful when you wish to keep the same buffer layout, but rotate the contents instead, especially when doing rotation animations between different orientations. The windowing system might use this value to determine the layout of system popups or dialogs. Visibility and Windowing system exposure.By default, the window is not visible, and you must call setVisible(true), or show() or similar to make it visible. To make a window hidden again, call setVisible(false) or hide(). The visible property describes the state the application wants the window to be in. Depending on the underlying system, a visible window might still not be shown on the screen. It could, for instance, be covered by other opaque windows or moved outside the physical area of the screen. On windowing systems that have exposure notifications, the isExposed() accessor describes whether the window should be treated as directly visible on screen. The exposeEvent() function is called whenever the windows exposure in the windowing system changes. On windowing systems that do not make this information visible to the application, isExposed() will simply return the same value as isVisible(). RenderingThere are two Qt APIs that can be used to render content into a window, QBackingStore for rendering with a QPainter and flushing the contents to a window with type QSurface::RasterSurface, and QOpenGLContext for rendering with OpenGL to a window with type QSurface::OpenGLSurface. The application can start rendering as soon as isExposed() returns true, and can keep rendering until it isExposed() returns false. To find out when isExposed() changes, reimplement exposeEvent(). The window will always get a resize event before the first expose event. Member Type Documentation
|
Constant | Value | Description |
---|---|---|
QWindow::ExcludeTransients | 0 | Transient parents are not considered ancestors. |
QWindow::IncludeTransients | 1 | Transient parents are considered ancestors. |
This property holds the orientation of the window's contents.
This is a hint to the window manager in case it needs to display additional content like popups, dialogs, status bars, or similar in relation to the window.
The recommended orientation is QScreen::orientation() but an application doesn't have to support all possible orientations, and thus can opt to ignore the current screen orientation.
The difference between the window and the content orientation determines how much to rotate the content by. QScreen::angleBetween(), QScreen::transformBetween(), and QScreen::mapBetween() can be used to compute the necessary transform.
The default value is Qt::PrimaryOrientation
Access functions:
Qt::ScreenOrientation | contentOrientation() const |
void | reportContentOrientationChange(Qt::ScreenOrientation orientation) |
Notifier signal:
void | contentOrientationChanged(Qt::ScreenOrientation orientation) |
See also requestWindowOrientation() and QScreen::orientation().
This property holds the cursor shape for this window.
The mouse cursor will assume this shape when it is over this window, unless an override cursor is set. See the list of predefined cursor objects for a range of useful shapes.
By default, this property contains a cursor with the Qt::ArrowCursor shape.
Some underlying window implementations will reset the cursor if it leaves a window even if the mouse is grabbed. If you want to have a cursor set for all windows, even when outside the window, consider QGuiApplication::setOverrideCursor().
Access functions:
QCursor | cursor() const |
void | setCursor(const QCursor &) |
void | unsetCursor() |
See also QGuiApplication::setOverrideCursor().
This property holds the height of the window's geometry.
Access functions:
int | height() const |
void | setHeight(int arg) |
Notifier signal:
void | heightChanged(int arg) |
This property holds whether the window is visible or not.
This property controls the visibility of the window in the windowing system.
By default, the window is not visible, you must call setVisible(true), or show() or similar to make it visible.
Access functions:
bool | isVisible() const |
void | setVisible(bool visible) |
Notifier signal:
void | visibleChanged(bool arg) |
See also show().
This property holds the width of the window's geometry.
Access functions:
int | width() const |
void | setWidth(int arg) |
Notifier signal:
void | widthChanged(int arg) |
Access functions:
QIcon | windowIcon() const |
void | setWindowIcon(const QIcon & icon) |
This property holds the modality of the window.
A modal window prevents other windows from receiving input events. Qt supports two types of modality: Qt::WindowModal and Qt::ApplicationModal.
By default, this property is Qt::NonModal
Access functions:
Qt::WindowModality | windowModality() const |
void | setWindowModality(Qt::WindowModality windowModality) |
Notifier signal:
void | windowModalityChanged(Qt::WindowModality windowModality) |
See also Qt::WindowModality.
This property holds the window's title in the windowing system.
The window title might appear in the title area of the window decorations, depending on the windowing system and the window flags. It might also be used by the windowing system to identify the window in other contexts, such as in the task switcher.
Access functions:
QString | windowTitle() const |
void | setWindowTitle(const QString &) |
See also windowFlags().
This property holds the x position of the window's geometry.
Access functions:
int | x() const |
void | setX(int arg) |
Notifier signal:
void | xChanged(int arg) |
This property holds the y position of the window's geometry.
Access functions:
int | y() const |
void | setY(int arg) |
Notifier signal:
void | yChanged(int arg) |
Creates a window as a top level on the given screen.
The window is not shown until setVisible(true), show(), or similar is called.
See also setScreen().
Creates a window as a child of the given parent window.
The window will be embedded inside the parent window, its coordinates relative to the parent.
The screen is inherited from the parent.
See also setParent().
Destroys the window.
Returns the base size of the window.
See also setBaseSize().
Close the window.
This closes the window, effectively calling destroy(), and potentially quitting the application
See also destroy() and QGuiApplication::quitOnLastWindowClosed().
Allocates the platform resources associated with the window.
It is at this point that the surface format set using setFormat() gets resolved into an actual native surface. However, the window remains hidden until setVisible() is called.
Note that it is not usually necessary to call this function directly, as it will be implicitly called by show(), setVisible(), and other functions that require access to the platform resources.
Call destroy() to free the platform resources if necessary.
See also destroy().
Releases the native platform resources associated with this window.
See also create().
Reimplemented from QObject::event().
Override this to handle any event sent to the window.
Remember to call the base class version if you wish for mouse events, key events, resize events, etc to be dispatched as usual.
The expose event is sent by the window system whenever the window's exposure on screen changes.
The application can start rendering into the window with QBackingStore and QOpenGLContext as soon as it gets an exposeEvent() such that isExposed() is true.
If the window is moved off screen, is made totally obscured by another window, iconified or similar, this function might be called and the value of isExposed() might change to false. When this happens, an application should stop its rendering as it is no longer visible to the user.
A resize event will always be sent before the expose event the first time a window is shown.
See also isExposed().
Override this to handle focus in events.
Focus in events are sent when the window receives keyboard focus.
See also focusOutEvent.
Returns the QObject that will be the final receiver of events tied focus, such as key events.
This signal is emitted when final receiver of events tied to focus is changed.
See also focusObject().
Override this to handle focus out events.
Focus out events are sent when the window loses keyboard focus.
See also focusInEvent.
Reimplemented from QSurface::format().
Returns the actual format of this window.
After the window has been created, this function will return the actual surface format of the window. It might differ from the requested format if the requested format could not be fulfilled by the platform.
See also setFormat(), create(), and requestedFormat().
Returns the geometry of the window, including its window frame.
See also geometry() and frameMargins().
Returns the window frame margins surrounding the window.
See also geometry() and frameGeometry().
Returns the top left position of the window, including its window frame.
This returns the same value as frameGeometry().topLeft().
See also setFramePos(), geometry(), and frameGeometry().
Returns the geometry of the window, excluding its window frame.
See also setGeometry(), frameMargins(), and frameGeometry().
Hides the window.
Equivalent to calling setVisible(false).
See also show() and setVisible().
Override this to handle hide evens.
The function is called when the window has requested being hidden in the windowing system.
Returns true if the window should appear active from a style perspective.
This is the case for the window that has input focus as well as windows that are in the same parent / transient parent chain as the focus window.
To get the window that currently has focus, use QGuiApplication::focusWindow().
Returns true if the window is an ancestor of the given child. If mode is IncludeTransients transient parents are also considered ancestors.
Returns if this window is exposed in the windowing system.
When the window is not exposed, it is shown by the application but it is still not showing in the windowing system, so the application should minimize rendering and other graphical activities.
An exposeEvent() is sent every time this value changes.
See also exposeEvent().
Returns whether the window is modal.
A modal window prevents other windows from getting any input.
See also QWindow::windowModality.
Returns whether the window is top level, i.e. has no parent window.
Override this to handle key press events.
See also keyReleaseEvent.
Override this to handle key release events.
See also keyPressEvent.
Lower the window in the windowing system.
Requests that the window be lowered to appear below other windows.
Translates the global screen coordinate pos to window coordinates.
See also mapToGlobal().
Translates the window coordinate pos to global screen coordinates. For example, mapToGlobal(QPoint(0,0)) would give the global coordinates of the top-left pixel of the window.
See also mapFromGlobal().
Returns the maximum size of the window.
See also setMaximumSize().
Returns the minimum size of the window.
See also setMinimumSize().
Override this to handle mouse double click events.
See also mousePressEvent() and QStyleHints::mouseDoubleClickInterval().
Override this to handle mouse move events.
Override this to handle mouse press events.
See also mouseReleaseEvent().
Override this to handle mouse release events.
See also mousePressEvent().
Override this to handle mouse events.
Override this to handle platform dependent events.
This might make your application non-portable.
Returns the parent window, if any.
A window without a parent is known as a top level window.
See also setParent().
See also setPos().
Raise the window in the windowing system.
Requests that the window be raised to appear above other windows.
Requests the window to be activated, i.e. receive keyboard focus.
See also isActive() and QGuiApplication::focusWindow().
Requests the given window orientation.
The window orientation specifies how the window should be rotated by the window manager in order to be displayed. Input events will be correctly mapped to the given orientation.
The return value is false if the system doesn't support the given orientation (for example when requesting a portrait orientation on a device that only handles landscape buffers, typically a desktop system).
If the return value is false, call windowOrientation() to get the actual supported orientation.
See also windowOrientation(), reportContentOrientationChange(), and QScreen::orientation().
Returns the requested surfaceformat of this window.
If the requested format was not supported by the platform implementation, the requestedFormat will differ from the actual window format.
This is the value set with setFormat().
See also setFormat() and format().
Sets the size of the window to be newSize.
See also setGeometry().
Override this to handle resize events.
The resize event is called whenever the window is resized in the windowing system, either directly through the windowing system acknowledging a setGeometry() or resize() request, or indirectly through the user resizing the window manually.
Returns the screen on which the window is shown.
The value returned will not change when the window is moved between virtual screens (as returned by QScreen::virtualSiblings()).
See also setScreen() and QScreen::virtualSiblings().
This signal is emitted when a window's screen changes, either by being set explicitly with setScreen(), or automatically when the window's screen is removed.
Sets the base size of the window.
The base size is used to calculate a proper window size if the window defines sizeIncrement().
See also setMinimumSize(), setMaximumSize(), setSizeIncrement(), and baseSize().
Sets the window's surface format.
The format determines properties such as color depth, alpha, depth and stencil buffer size, etc.
See also format().
Sets the upper left position of the window including its window frame.
See also framePos(), setGeometry(), and frameGeometry().
See also geometry().
Sets the geometry of the window, excluding its window frame, to rect.
To make sure the window is visible, make sure the geometry is within the virtual geometry of its screen.
See also geometry(), screen(), and QScreen::virtualGeometry().
Set whether keyboard grab should be enabled or not.
If the return value is true, the window receives all key events until setKeyboardGrabEnabled(false) is called; other windows get no key events at all. Mouse events are not affected. Use setMouseGrabEnabled() if you want to grab that.
See also setMouseGrabEnabled().
Sets the maximum size of the window.
This is a hint to the window manager to prevent resizing above the specified size.
See also setMinimumSize() and maximumSize().
Sets the minimum size of the window.
This is a hint to the window manager to prevent resizing below the specified size.
See also setMaximumSize() and minimumSize().
Sets whether mouse grab should be enabled or not.
If the return value is true, the window receives all mouse events until setMouseGrabEnabled(false) is called; other windows get no mouse events at all. Keyboard events are not affected. Use setKeyboardGrabEnabled() if you want to grab that.
See also setKeyboardGrabEnabled().
Sets the window's opacity in the windowing system to level.
If the windowing system supports window opacity, this can be used to fade the window in and out, or to make it semitransparent.
A value of 1.0 or above is treated as fully opaque, whereas a value of 0.0 or below is treated as fully transparent. Values inbetween represent varying levels of translucency between the two extremes.
Sets the parent Window. This will lead to the windowing system managing the clip of the window, so it will be clipped to the parent window.
Setting parent to be 0 will make the window become a top level window.
See also parent().
See also pos().
Sets the screen on which the window should be shown.
If the window has been created, it will be recreated on the new screen.
Note that if the screen is part of a virtual desktop of multiple screens, the window can appear on any of the screens returned by QScreen::virtualSiblings().
See also screen() and QScreen::virtualSiblings().
Sets the size increment of the window.
When the user resizes the window, the size will move in steps of sizeIncrement().width() pixels horizontally and sizeIncrement().height() pixels vertically, with baseSize() as the basis.
By default, this property contains a size with zero width and height.
The windowing system might not support size increments.
See also sizeIncrement(), setBaseSize(), setMinimumSize(), and setMaximumSize().
Set the surfaceType of the window.
Specifies whether the window is meant for raster rendering with QBackingStore, or OpenGL rendering with QOpenGLContext.
See also surfaceType(), QBackingStore, and QOpenGLContext.
Sets the transient parent
This is a hint to the window manager that this window is a dialog or pop-up on behalf of the given window.
See also transientParent() and parent().
Sets the window flags of the window to flags.
The window flags control the window's appearance in the windowing system, whether it's a dialog, popup, or a regular window, and whether it should have a title bar, etc.
See also windowFlags().
Sets the desired window state.
The window state represents whether the window appears in the windowing system as maximized, minimized, fullscreen, or normal.
The enum value Qt::WindowActive is not an accepted parameter.
See also windowState(), showNormal(), showFullScreen(), showMinimized(), and showMaximized().
Shows the window.
This equivalent to calling showFullScreen() or showNormal(), depending on whether the platform defaults to windows being fullscreen or not.
See also showFullScreen(), showNormal(), hide(), and QStyleHints::showIsFullScreen().
Override this to handle show events.
The function is called when the window has requested becoming visible.
If the window is successfully shown by the windowing system, this will be followed by a resize and an expose event.
Shows the window as fullscreen.
Equivalent to calling setWindowState(Qt::WindowFullScreen) and then setVisible(true).
See also setWindowState() and setVisible().
Shows the window as maximized.
Equivalent to calling setWindowState(Qt::WindowMaximized) and then setVisible(true).
See also setWindowState() and setVisible().
Shows the window as minimized.
Equivalent to calling setWindowState(Qt::WindowMinimized) and then setVisible(true).
See also setWindowState() and setVisible().
Shows the window as normal, i.e. neither maximized, minimized, nor fullscreen.
Equivalent to calling setWindowState(Qt::WindowNoState) and then setVisible(true).
See also setWindowState() and setVisible().
Returns the size increment of the window.
See also setSizeIncrement().
Reimplemented from QSurface::surfaceType().
Returns the surface type of the window.
See also setSurfaceType().
Override this to handle touch events.
Returns the transient parent of the window.
See also setTransientParent() and parent().
Override this to handle mouse wheel or other wheel events.
Returns the window's platform id.
For platforms where this id might be useful, the value returned will uniquely represent the window inside the corresponding screen.
See also screen().
Returns the window flags of the window.
This might differ from the flags set with setWindowFlags() if the requested flags could not be fulfilled.
See also setWindowFlags().
Returns the actual window orientation.
The default value is Qt::PrimaryOrientation.
See also requestWindowOrientation().
Returns the window state.
See also setWindowState().
Returns the type of the window.
This returns the part of the window flags that represents whether the window is a dialog, tooltip, popup, regular window, etc.
See also windowFlags() and setWindowFlags().