6.0.0-rc4Source

QWindow Class

The QWindow class represents a window in the underlying windowing system. More…

Header#include <QWindow>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes
InheritsQObject, QSurface
Inherited byQPaintDeviceWindow

List of all members, including inherited members

Public Functions

QWindow(QScreen *screen = nullptr)
~QWindow()
quintptrwinId() const
voidcreate()
voiddestroy()
boolisTopLevel() const
QStringtitle() const
voidsetTitle(const QString &title)
QWindow *transientParent() const
voidsetTransientParent(QWindow *parent)
boolisVisible() const
boolisExposed() const
boolisActive() const
QScreen *screen() const
qrealdevicePixelRatio() const
QRectgeometry() const
voidsetGeometry(const QRect &rect)
voidsetGeometry(int x, int y, int w, int h)
QPointposition() const
voidsetPosition(const QPoint &pt)
voidsetPosition(int x, int y)
voidresize(const QSize &newSize)
voidresize(int w, int h)
intx() const
inty() const
intwidth() const
intheight() const
voidsetX(int arg)
voidsetY(int arg)
voidsetWidth(int arg)
voidsetHeight(int arg)
QPointmapToGlobal(const QPoint &pos) const
QPointmapFromGlobal(const QPoint &pos) const
QPlatformWindow *handle() const
voidsetSurfaceType(QSurface::SurfaceType surfaceType)
voidsetFormat(const QSurfaceFormat &format)
QSurfaceFormatrequestedFormat() const
QCursorcursor() const
voidsetCursor(const QCursor &cursor)
voidunsetCursor()

Reimplemented Public Functions

Public Slots

voidsetVisible(bool visible)
voidshow()
voidhide()
boolclose()
voidraise()
voidrequestActivate()
voidrequestUpdate()

Signals

voidvisibleChanged(bool arg)
voidtitleChanged(const QString &title)
voidtransientParentChanged(QWindow *transientParent)
voidxChanged(int arg)
voidyChanged(int arg)
voidwidthChanged(int arg)
voidheightChanged(int arg)
voidactiveChanged(bool active)

Protected Functions

virtual voidexposeEvent(QExposeEvent *event)
virtual voidresizeEvent(QResizeEvent *event)
virtual voidmoveEvent(QMoveEvent *event)
virtual voidfocusInEvent(QFocusEvent *event)
virtual voidfocusOutEvent(QFocusEvent *event)
virtual voidshowEvent(QShowEvent *event)
virtual voidhideEvent(QHideEvent *event)
virtual voidcloseEvent(QCloseEvent *event)
virtual voidkeyPressEvent(QKeyEvent *event)
virtual voidkeyReleaseEvent(QKeyEvent *event)
virtual voidmousePressEvent(QMouseEvent *event)
virtual voidmouseReleaseEvent(QMouseEvent *event)
virtual voidmouseDoubleClickEvent(QMouseEvent *event)
virtual voidmouseMoveEvent(QMouseEvent *event)
virtual voidwheelEvent(QWheelEvent *event)

Reimplemented Protected Functions

boolevent(QEvent *event)

Detailed Description

A window is a rectangle on a screen that the windowing system manages. It receives events, such as mouse and key events, and shows what an application paints into it. QWindow itself paints nothing: subclass QRasterWindow, or draw with a QBackingStore.

QWindow window;
window.setTitle("Hello");
window.resize(320, 240);
window.show();

Handle input by reimplementing the event functions:

class MyWindow : public QWindow {
protected:
    void mousePressEvent(QMouseEvent *event) override { qDebug() << event->pos(); }
};

See also QRasterWindow, QBackingStore, QScreen and QGuiApplication.

Differences from Qt

Only top-level windows exist: there is no parent window, no window flags or modality, no setMinimumSize(), cursor, icon or opacity, no window states and no Vulkan, Metal or Direct3D surface. OpenGL surfaces work through EGL; see QOpenGLContext. close() destroys the platform window; showing the window again creates it anew. There is no requestUpdate() throttling to the display refresh rate.

Member Function Documentation

[explicit] QWindow::QWindow(QScreen *screen = nullptr)

Constructs a top-level window on screen, or on the primary screen if screen is nullptr. A QGuiApplication must exist. The window is not visible.

[override] QWindow::~QWindow()

Destroys the window, which also hides it.

[signal] void QWindow::activeChanged(bool active)

This signal is emitted when the window becomes the active window or stops being it; active tells which.

[slot] bool QWindow::close()

Sends the window a close event. If the window accepts it, which it does by default, the window is destroyed and the function returns true.

The application quits when the last window closes and QGuiApplication::quitOnLastWindowClosed() is true.

See also destroy() and closeEvent().

[virtual, protected] void QWindow::closeEvent(QCloseEvent *event)

Handles the close event event. Call event->ignore() to keep the window open. The default accepts the event.

See also close().

void QWindow::create()

Creates the platform window. show() does this when needed, so calling create() is only necessary to get a winId() before showing the window. A window with an empty geometry gets a size of 160 by 160.

See also destroy() and winId().

QCursor QWindow::cursor() const

Returns the cursor that shows while the mouse is over the window: the standard arrow, unless setCursor() set another one.

See also setCursor() and unsetCursor().

void QWindow::destroy()

Hides the window and releases the platform window. The window object stays, and show() creates the platform window again.

See also create().

qreal QWindow::devicePixelRatio() const

Returns the number of pixels of the screen that one unit of the window's coordinates covers; see QScreen::devicePixelRatio(). It is 1 if the window has no screen.

[override, protected] bool QWindow::event(QEvent *event)

Reimplements QObject::event().

Handles event and returns true if it was recognized. It calls the event handlers such as mousePressEvent() and keyPressEvent().

[virtual, protected] void QWindow::exposeEvent(QExposeEvent *event)

Handles an expose event: part of the window became visible, and the window has to draw it. event holds the region. The default does nothing.

See also isExposed().

[virtual, protected] void QWindow::focusInEvent(QFocusEvent *event)

Handles the focus-in event event: the window got the keyboard focus. The default does nothing.

[virtual, protected] void QWindow::focusOutEvent(QFocusEvent *event)

Handles the focus-out event event: the window lost the keyboard focus. The default does nothing.

[override] QSurfaceFormat QWindow::format() const

Reimplements QSurface::format().

Returns the format the window has: the requested format until an OpenGL context is made current on the window, and then the format of the buffers the window system gave it.

See also requestedFormat().

QRect QWindow::geometry() const

Returns the geometry of the window in screen coordinates.

See also setGeometry().

QPlatformWindow * QWindow::handle() const

Returns the platform window, or nullptr if the window has not been created. The type is private to Nt.

See also create().

int QWindow::height() const

Returns the height of the window in pixels.

See also setHeight().

[signal] void QWindow::heightChanged(int arg)

This signal is emitted when the height changes to arg.

[slot] void QWindow::hide()

Hides the window. This is the same as setVisible(false).

See also show().

[virtual, protected] void QWindow::hideEvent(QHideEvent *event)

Handles the hide event event: the window was hidden. The default does nothing.

bool QWindow::isActive() const

Returns true if the window is the active window.

See also requestActivate().

bool QWindow::isExposed() const

Returns true if the window is visible and its contents are on the screen, so that painting makes sense. It becomes true when the first expose event arrives.

See also isVisible() and exposeEvent().

bool QWindow::isTopLevel() const

Returns true, because every window is a top-level window.

bool QWindow::isVisible() const

Returns true if the window is visible: shown, not hidden or closed.

See also setVisible() and isExposed().

[virtual, protected] void QWindow::keyPressEvent(QKeyEvent *event)

Handles the key press event. The default ignores the event.

See also keyReleaseEvent().

[virtual, protected] void QWindow::keyReleaseEvent(QKeyEvent *event)

Handles the key release event. The default ignores the event.

See also keyPressEvent().

QPoint QWindow::mapFromGlobal(const QPoint &pos) const

Returns pos, a point on the screen, as a point in the window.

See also mapToGlobal().

QPoint QWindow::mapToGlobal(const QPoint &pos) const

Returns pos, a point in the window, as a point on the screen.

See also mapFromGlobal().

[virtual, protected] void QWindow::mouseDoubleClickEvent(QMouseEvent *event)

Handles the double click event. The default ignores the event.

[virtual, protected] void QWindow::mouseMoveEvent(QMouseEvent *event)

Handles the mouse move event. The default ignores the event.

[virtual, protected] void QWindow::mousePressEvent(QMouseEvent *event)

Handles the mouse button press event. The default ignores the event.

See also mouseReleaseEvent().

[virtual, protected] void QWindow::mouseReleaseEvent(QMouseEvent *event)

Handles the mouse button release event. The default ignores the event.

See also mousePressEvent().

[virtual, protected] void QWindow::moveEvent(QMoveEvent *event)

Handles the move event event. The default does nothing.

See also setPosition().

QPoint QWindow::position() const

Returns the position of the top left corner of the window.

See also setPosition().

[slot] void QWindow::raise()

Asks the window system to put the window in front of the others.

[slot] void QWindow::requestActivate()

Asks the window system to give the window the keyboard focus. The window is active once isActive() returns true.

See also isActive().

QSurfaceFormat QWindow::requestedFormat() const

Returns the format set with setFormat(), or QSurfaceFormat::defaultFormat() if none was set.

This function was introduced in 6.0.

See also setFormat() and format().

[slot] void QWindow::requestUpdate()

Posts an UpdateRequest event to the window, once, however often this is called before the event is delivered.

void QWindow::resize(const QSize &newSize)

Resizes the window to newSize.

See also size() and setGeometry().

void QWindow::resize(int w, int h)

This is an overloaded function.

Resizes the window to w by h pixels.

[virtual, protected] void QWindow::resizeEvent(QResizeEvent *event)

Handles the resize event event. The default does nothing.

See also resize().

QScreen * QWindow::screen() const

Returns the screen the window is on.

void QWindow::setCursor(const QCursor &cursor)

Sets the cursor that shows while the mouse is over the window to cursor. An override cursor of the application shows instead for as long as there is one; see QGuiApplication::setOverrideCursor().

See also cursor() and unsetCursor().

void QWindow::setFormat(const QSurfaceFormat &format)

Sets the format the window asks for to format: its depth, stencil and multisample buffers, the OpenGL version and the swap interval. Set it before an OpenGL context is first made current on the window.

This function was introduced in 6.0.

See also requestedFormat() and format().

void QWindow::setGeometry(const QRect &rect)

Sets the geometry of the window to rect, in screen coordinates. The window receives a move and a resize event as far as the position and size change. The windowing system may adjust the geometry later.

See also geometry(), resize() and setPosition().

void QWindow::setGeometry(int x, int y, int w, int h)

This is an overloaded function.

Sets the geometry to the rectangle at (x, y) of w by h.

void QWindow::setHeight(int arg)

Sets the height of the window to arg pixels.

See also height().

void QWindow::setPosition(const QPoint &pt)

Moves the window to pt.

See also position() and setGeometry().

void QWindow::setPosition(int x, int y)

This is an overloaded function.

Moves the window to (x, y).

void QWindow::setSurfaceType(QSurface::SurfaceType surfaceType)

Sets the kind of surface of the window to surfaceType. Set it to QSurface::OpenGLSurface before the window is created to render into it with a QOpenGLContext; QOpenGLWindow does that itself.

This function was introduced in 6.0.

See also surfaceType() and QOpenGLContext::makeCurrent().

void QWindow::setTitle(const QString &title)

Sets the window title to title.

See also title().

void QWindow::setTransientParent(QWindow *parent)

Makes the window transient for parent: the window system keeps it above parent and treats it as a dialog of it. With nullptr the window is a normal window again.

See also transientParent().

[slot] void QWindow::setVisible(bool visible)

Shows the window if visible is true and hides it otherwise. Showing creates the platform window if needed.

See also show() and hide().

void QWindow::setWidth(int arg)

Sets the width of the window to arg pixels.

See also width().

void QWindow::setX(int arg)

Sets the x position of the window to arg.

See also x().

void QWindow::setY(int arg)

Sets the y position of the window to arg.

See also y().

[slot] void QWindow::show()

Shows the window. This is the same as setVisible(true).

See also hide().

[virtual, protected] void QWindow::showEvent(QShowEvent *event)

Handles the show event event: the window is about to become visible. The default does nothing.

[override] QSize QWindow::size() const

Reimplements QSurface::size().

Returns the size of the window in pixels.

See also resize().

[override] QSurface::SurfaceType QWindow::surfaceType() const

Reimplements QSurface::surfaceType().

Returns the kind of surface of the window. The default is QSurface::RasterSurface.

See also setSurfaceType().

QString QWindow::title() const

Returns the window title.

See also setTitle().

[signal] void QWindow::titleChanged(const QString &title)

This signal is emitted when the title changes to title.

QWindow * QWindow::transientParent() const

Returns the window that this window is transient for, or nullptr if it is a normal window.

See also setTransientParent().

[signal] void QWindow::transientParentChanged(QWindow *transientParent)

This signal is emitted when the transient parent of the window changes to transientParent.

void QWindow::unsetCursor()

Gives the window the standard arrow cursor again.

See also setCursor().

[signal] void QWindow::visibleChanged(bool arg)

This signal is emitted when the window is shown or hidden; arg is the new visibility.

[virtual, protected] void QWindow::wheelEvent(QWheelEvent *event)

Handles the mouse wheel turn event. The default ignores the event.

int QWindow::width() const

Returns the width of the window in pixels.

See also setWidth().

[signal] void QWindow::widthChanged(int arg)

This signal is emitted when the width changes to arg.

quintptr QWindow::winId() const

Returns the identifier the windowing system uses for the window, or 0 if it has not been created.

See also create().

int QWindow::x() const

Returns the x position of the window.

See also setX().

[signal] void QWindow::xChanged(int arg)

This signal is emitted when the x position changes to arg.

int QWindow::y() const

Returns the y position of the window.

See also setY().

[signal] void QWindow::yChanged(int arg)

This signal is emitted when the y position changes to arg.