QWindow Class
The QWindow class represents a window in the underlying windowing system. More…
| Header | #include <QWindow> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Gui) |
| Module | Nt GUI C++ Classes |
| Inherits | QObject, QSurface |
| Inherited by | QPaintDeviceWindow |
List of all members, including inherited members
Public Functions
| QWindow(QScreen *screen = nullptr) | |
| ~QWindow() | |
| quintptr | winId() const |
| void | create() |
| void | destroy() |
| bool | isTopLevel() const |
| QString | title() const |
| void | setTitle(const QString &title) |
| QWindow * | transientParent() const |
| void | setTransientParent(QWindow *parent) |
| bool | isVisible() const |
| bool | isExposed() const |
| bool | isActive() const |
| QScreen * | screen() const |
| qreal | devicePixelRatio() const |
| QRect | geometry() const |
| void | setGeometry(const QRect &rect) |
| void | setGeometry(int x, int y, int w, int h) |
| QPoint | position() const |
| void | setPosition(const QPoint &pt) |
| void | setPosition(int x, int y) |
| void | resize(const QSize &newSize) |
| void | resize(int w, int h) |
| int | x() const |
| int | y() const |
| int | width() const |
| int | height() const |
| void | setX(int arg) |
| void | setY(int arg) |
| void | setWidth(int arg) |
| void | setHeight(int arg) |
| QPoint | mapToGlobal(const QPoint &pos) const |
| QPoint | mapFromGlobal(const QPoint &pos) const |
| QPlatformWindow * | handle() const |
| void | setSurfaceType(QSurface::SurfaceType surfaceType) |
| void | setFormat(const QSurfaceFormat &format) |
| QSurfaceFormat | requestedFormat() const |
| QCursor | cursor() const |
| void | setCursor(const QCursor &cursor) |
| void | unsetCursor() |
Reimplemented Public Functions
| QSize | size() const |
| QSurface::SurfaceType | surfaceType() const |
| QSurfaceFormat | format() const |
Public Slots
| void | setVisible(bool visible) |
| void | show() |
| void | hide() |
| bool | close() |
| void | raise() |
| void | requestActivate() |
| void | requestUpdate() |
Signals
| void | visibleChanged(bool arg) |
| void | titleChanged(const QString &title) |
| void | transientParentChanged(QWindow *transientParent) |
| void | xChanged(int arg) |
| void | yChanged(int arg) |
| void | widthChanged(int arg) |
| void | heightChanged(int arg) |
| void | activeChanged(bool active) |
Protected Functions
| virtual void | exposeEvent(QExposeEvent *event) |
| virtual void | resizeEvent(QResizeEvent *event) |
| virtual void | moveEvent(QMoveEvent *event) |
| virtual void | focusInEvent(QFocusEvent *event) |
| virtual void | focusOutEvent(QFocusEvent *event) |
| virtual void | showEvent(QShowEvent *event) |
| virtual void | hideEvent(QHideEvent *event) |
| virtual void | closeEvent(QCloseEvent *event) |
| virtual void | keyPressEvent(QKeyEvent *event) |
| virtual void | keyReleaseEvent(QKeyEvent *event) |
| virtual void | mousePressEvent(QMouseEvent *event) |
| virtual void | mouseReleaseEvent(QMouseEvent *event) |
| virtual void | mouseDoubleClickEvent(QMouseEvent *event) |
| virtual void | mouseMoveEvent(QMouseEvent *event) |
| virtual void | wheelEvent(QWheelEvent *event) |
Reimplemented Protected Functions
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
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.
QWindow::~QWindow()
Destroys the window, which also hides it.
void QWindow::activeChanged(bool active)
This signal is emitted when the window becomes the active window or stops being it; active tells which.
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().
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.
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().
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().
void QWindow::focusInEvent(QFocusEvent *event)
Handles the focus-in event event: the window got the keyboard focus. The default does nothing.
void QWindow::focusOutEvent(QFocusEvent *event)
Handles the focus-out event event: the window lost the keyboard focus. The default does nothing.
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().
void QWindow::heightChanged(int arg)
This signal is emitted when the height changes to arg.
void QWindow::hide()
Hides the window. This is the same as setVisible(false).
See also show().
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().
void QWindow::keyPressEvent(QKeyEvent *event)
Handles the key press event. The default ignores the event.
See also keyReleaseEvent().
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().
void QWindow::mouseDoubleClickEvent(QMouseEvent *event)
Handles the double click event. The default ignores the event.
void QWindow::mouseMoveEvent(QMouseEvent *event)
Handles the mouse move event. The default ignores the event.
void QWindow::mousePressEvent(QMouseEvent *event)
Handles the mouse button press event. The default ignores the event.
See also mouseReleaseEvent().
void QWindow::mouseReleaseEvent(QMouseEvent *event)
Handles the mouse button release event. The default ignores the event.
See also mousePressEvent().
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().
void QWindow::raise()
Asks the window system to put the window in front of the others.
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().
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.
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().
void QWindow::setVisible(bool visible)
Shows the window if visible is true and hides it otherwise. Showing creates the platform window if needed.
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().
void QWindow::show()
Shows the window. This is the same as setVisible(true).
See also hide().
void QWindow::showEvent(QShowEvent *event)
Handles the show event event: the window is about to become visible. The default does nothing.
QSize QWindow::size() const
Reimplements QSurface::size().
Returns the size of the window in pixels.
See also resize().
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().
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().
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().
void QWindow::visibleChanged(bool arg)
This signal is emitted when the window is shown or hidden; arg is the new visibility.
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().
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().
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().
void QWindow::yChanged(int arg)
This signal is emitted when the y position changes to arg.