QWindow 类

QWindow 类表示在底层窗口系统中的窗口。 更多...

头: #include <QWindow>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QObject and QSurface
继承者:

QPaintDeviceWindow , QQuickWindow ,和 QVulkanWindow

公共类型

enum AncestorMode { ExcludeTransients, IncludeTransients }
enum Visibility { Windowed, Minimized, Maximized, FullScreen, AutomaticVisibility, Hidden }

特性

公共函数

QWindow (QScreen * targetScreen = nullptr)
QWindow (QWindow * parent )
virtual ~QWindow ()
QSize baseSize () const
Qt::ScreenOrientation contentOrientation () const
void create ()
QCursor cursor () const
void destroy ()
qreal devicePixelRatio () const
QString filePath () const
Qt::WindowFlags flags () const
virtual QObject * focusObject () const
QRect frameGeometry () const
QMargins frameMargins () const
QPoint framePosition () const
QRect geometry () const
int height () const
QIcon icon () const
bool isActive () const
bool isAncestorOf (const QWindow * child , QWindow::AncestorMode mode = IncludeTransients) const
bool isExposed () const
bool isModal () const
bool isTopLevel () const
bool isVisible () const
(从 6.0 起) QPointF mapFromGlobal (const QPointF & pos ) const
QPoint mapFromGlobal (const QPoint & pos ) const
(从 6.0 起) QPointF mapToGlobal (const QPointF & pos ) const
QPoint mapToGlobal (const QPoint & pos ) const
QRegion mask () const
int maximumHeight () const
QSize maximumSize () const
int maximumWidth () const
int minimumHeight () const
QSize minimumSize () const
int minimumWidth () const
Qt::WindowModality modality () const
qreal opacity () const
QWindow * parent (QWindow::AncestorMode mode = ExcludeTransients) const
QPoint position () const
void reportContentOrientationChange (Qt::ScreenOrientation orientation )
QSurfaceFormat requestedFormat () const
void resize (const QSize & newSize )
void resize (int w , int h )
QScreen * screen () const
void setBaseSize (const QSize & size )
void setCursor (const QCursor & cursor )
void setFilePath (const QString & filePath )
void setFlag (Qt::WindowType flag , bool on = true)
void setFlags (Qt::WindowFlags flags )
void setFormat (const QSurfaceFormat & format )
void setFramePosition (const QPoint & point )
void setIcon (const QIcon & icon )
bool setKeyboardGrabEnabled (bool grab )
void setMask (const QRegion & region )
void setMaximumSize (const QSize & size )
void setMinimumSize (const QSize & size )
void setModality (Qt::WindowModality modality )
bool setMouseGrabEnabled (bool grab )
void setOpacity (qreal level )
void setParent (QWindow * parent )
void setPosition (const QPoint & pt )
void setPosition (int posx , int posy )
void setScreen (QScreen * newScreen )
void setSizeIncrement (const QSize & size )
void setSurfaceType (QSurface::SurfaceType surfaceType )
void setTransientParent (QWindow * parent )
void setVisibility (QWindow::Visibility v )
void setVulkanInstance (QVulkanInstance * 实例 )
void setWindowState (Qt::WindowState state )
void setWindowStates (Qt::WindowStates state )
QSize sizeIncrement () const
QString title () const
QWindow * transientParent () const
Qt::WindowType type () const
void unsetCursor ()
QWindow::Visibility visibility () const
QVulkanInstance * vulkanInstance () const
int width () const
WId winId () const
Qt::WindowState windowState () const
Qt::WindowStates windowStates () const
int x () const
int y () const

重实现公共函数

virtual QSurfaceFormat format () const override
virtual QSize size () const override
virtual QSurface::SurfaceType surfaceType () const override

公共槽

void alert (int msec )
bool close ()
void hide ()
void lower ()
void raise ()
void requestActivate ()
void requestUpdate ()
void setGeometry (int posx , int posy , int w , int h )
void setGeometry (const QRect & rect )
void setHeight (int arg )
void setMaximumHeight (int h )
void setMaximumWidth (int w )
void setMinimumHeight (int h )
void setMinimumWidth (int w )
void setTitle (const QString &)
void setVisible (bool visible )
void setWidth (int arg )
void setX (int arg )
void setY (int arg )
void show ()
void showFullScreen ()
void showMaximized ()
void showMinimized ()
void showNormal ()
bool startSystemMove ()
bool startSystemResize (Qt::Edges edges )

信号

void activeChanged ()
void contentOrientationChanged (Qt::ScreenOrientation orientation )
void focusObjectChanged (QObject * object )
void heightChanged (int arg )
void maximumHeightChanged (int arg )
void maximumWidthChanged (int arg )
void minimumHeightChanged (int arg )
void minimumWidthChanged (int arg )
void modalityChanged (Qt::WindowModality modality )
void opacityChanged (qreal opacity )
void screenChanged (QScreen * screen )
void transientParentChanged (QWindow * transientParent )
void visibilityChanged (QWindow::Visibility visibility )
void visibleChanged (bool arg )
void widthChanged (int arg )
void windowStateChanged (Qt::WindowState windowState )
void windowTitleChanged (const QString & title )
void xChanged (int arg )
void yChanged (int arg )

静态公共成员

QWindow * fromWinId (WId id )

保护函数

virtual void closeEvent (QCloseEvent * ev )
virtual void exposeEvent (QExposeEvent * ev )
virtual void focusInEvent (QFocusEvent * ev )
virtual void focusOutEvent (QFocusEvent * ev )
virtual void hideEvent (QHideEvent * ev )
virtual void keyPressEvent (QKeyEvent * ev )
virtual void keyReleaseEvent (QKeyEvent * ev )
virtual void mouseDoubleClickEvent (QMouseEvent * ev )
virtual void mouseMoveEvent (QMouseEvent * ev )
virtual void mousePressEvent (QMouseEvent * ev )
virtual void mouseReleaseEvent (QMouseEvent * ev )
virtual void moveEvent (QMoveEvent * ev )
virtual bool nativeEvent (const QByteArray & eventType , void * message , qintptr * result )
(从 6.0 起) virtual void paintEvent (QPaintEvent * ev )
virtual void resizeEvent (QResizeEvent * ev )
virtual void showEvent (QShowEvent * ev )
virtual void tabletEvent (QTabletEvent * ev )
virtual void touchEvent (QTouchEvent * ev )
virtual void wheelEvent (QWheelEvent * ev )

重实现保护函数

virtual bool event (QEvent * ev ) override

详细描述

供给父级的窗口,将变成其父级窗口的本机子级窗口。

应用程序通常使用 QWidget or QQuickView 为其 UI,而不是 QWindow 直接。仍然是可能的直接渲染到 QWindow 采用 QBackingStore or QOpenGLContext ,当希望把依赖关系降到最低 (或想要直接使用 OpenGL) 时。 光栅窗口范例 and OpenGL 窗口范例 是有用参考范例为如何渲染到 QWindow 使用任一方式。

资源管理

窗口可以潜在使用大量内存。度量通常是宽度乘以高度,乘以颜色深度。窗口还可能包括多个缓冲,以支持双缓冲和三缓冲,及深度和蜡纸缓冲。要释放窗口内存资源,调用 destroy () 函数。

内容取向

QWindow 拥有 reportContentOrientationChange () 可以用于指定窗口内容相对屏幕的布局。内容取向只需对窗口系统提示窗口内容的取向。它很有用当希望保持相同窗口大小,却取而代之旋转内容,尤其是做不同取向之间的旋转动画时。窗口系统可以使用此值,以确定系统弹出窗口 (或对话框) 的布局。

可见性和窗口系统暴露

默认情况下,窗口不可见,且必须调用 setVisible (true),或 show () 或类似的以使之可见。要使窗口再次被隐藏,调用 setVisible (false) 或 hide ()。visible 特性描述应用程序想要窗口所处的状态。从属底层系统,可能仍不会在屏幕中展示可见窗口。例如,它可能被其它不透明窗口所覆盖,或被移到屏幕物理区域外。在拥有暴露通知的窗口系统, isExposed () 访问器描述窗口是否应该被视为在屏幕中直接可见。 exposeEvent () 函数被调用每当窗口区域无效时 (例如:由于窗口系统暴露的改变)。在不让此信息对应用程序可见的窗口系统, isExposed () 只需返回相同值如 isVisible ().

QWindow::Visibility 查询透过 visibility () 是方便 API 组合函数 visible() 和 windowStates ().

渲染

有 2 个 Qt API 可以用于将内容渲染到窗口, QBackingStore 渲染时采用 QPainter 并将内容刷新到窗口按类型 QSurface::RasterSurface ,和 QOpenGLContext 渲染采用 OpenGL 到窗口按类型 QSurface::OpenGLSurface .

应用程序可以尽快启动渲染当 isExposed () 返回 true ,且可以保持渲染直到其 isExposed () 返回 false 。要找出何时 isExposed () 改变,重实现 exposeEvent ()。窗口会始终获取重置大小事件,在首个暴露事件之前。

初始几何体

若窗口的宽度和高度未初始化,窗口将从平台窗口获得合理默认几何体。若位置未初始化,则平台窗口将允许窗口系统定位窗口。例如,在 X11,窗口管理器通常会做某种智能定位,以试着避免有新窗口完全遮盖现有窗口。不管怎样 setGeometry () 初始化位置和大小两者,所以若需要固定大小而非自动位置,应该调用 resize () 或 setWidth () 和 setHeight () 代替。

成员类型文档编制

enum QWindow:: AncestorMode

此枚举用于控制是否应该将瞬时父级认为是祖先。

常量 描述
QWindow::ExcludeTransients 0 瞬时父级不被认为是祖先。
QWindow::IncludeTransients 1 瞬时父级被认为是祖先。

enum QWindow:: Visibility

此枚举描述窗口占据 (或应该占据) 屏幕的什么部分。

常量 描述
QWindow::Windowed 2 The window occupies part of the screen, but not necessarily the entire screen. This state will occur only on windowing systems which support showing multiple windows simultaneously. In this state it is possible for the user to move and resize the window manually, if WindowFlags permit it and if it is supported by the windowing system.
QWindow::Minimized 3 The window is reduced to an entry or icon on the task bar, dock, task list or desktop, depending on how the windowing system handles minimized windows.
QWindow::Maximized 4 The window occupies one entire screen, and the titlebar is still visible. On most windowing systems this is the state achieved by clicking the maximize button on the toolbar.
QWindow::FullScreen 5 The window occupies one entire screen, is not resizable, and there is no titlebar. On some platforms which do not support showing multiple simultaneous windows, this can be the usual visibility when the window is not hidden.
QWindow::AutomaticVisibility 1 This means to give the window a default visible state, which might be fullscreen or windowed depending on the platform. It can be given as a parameter to setVisibility but will never be read back from the visibility accessor.
QWindow::Hidden 0 窗口无论如何不可见,不管怎样,它可能记住可以通过设置 AutomaticVisibility 还原的潜在可见性。

特性文档编制

[read-only] active : const bool

此特性保持窗口的活动状态

访问函数:

bool isActive () const

通知程序信号:

void activeChanged ()

另请参阅 requestActivate ().

contentOrientation : Qt::ScreenOrientation

此特性保持窗口内容的取向

这是窗口管理器的提示,若它需要显示相关窗口的额外内容 (像:弹出窗口、对话框、状态栏或类似的)。

推荐取向为 QScreen::orientation () 但应用程序不必支持所有可能取向,因此可以选择忽略当前屏幕取向。

窗口和内容取向之间的差异,确定内容的旋转量。 QScreen::angleBetween (), QScreen::transformBetween (),和 QScreen::mapBetween () 可以用于计算必要变换。

默认值为 Qt::PrimaryOrientation

访问函数:

Qt::ScreenOrientation contentOrientation () const
void reportContentOrientationChange (Qt::ScreenOrientation orientation )

通知程序信号:

void contentOrientationChanged (Qt::ScreenOrientation orientation )

flags : Qt::WindowFlags

此特性保持窗口的窗口标志

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.

The actual window flags might differ from the flags set with setFlags() if the requested flags could not be fulfilled.

访问函数:

Qt::WindowFlags flags () const
void setFlags (Qt::WindowFlags flags )

另请参阅 setFlag ().

height : int

此特性保持窗口几何体的高度

访问函数:

int height () const
void setHeight (int arg )

通知程序信号:

void heightChanged (int arg )

maximumHeight : int

此特性保持窗口几何体的最大高度

访问函数:

int maximumHeight () const
void setMaximumHeight (int h )

通知程序信号:

void maximumHeightChanged (int arg )

maximumWidth : int

This property holds the maximum width of the window's geometry

访问函数:

int maximumWidth () const
void setMaximumWidth (int w )

通知程序信号:

void maximumWidthChanged (int arg )

minimumHeight : int

此特性保持窗口几何体的最小高度

访问函数:

int minimumHeight () const
void setMinimumHeight (int h )

通知程序信号:

void minimumHeightChanged (int arg )

minimumWidth : int

此特性保持窗口几何体的最小宽度

访问函数:

int minimumWidth () const
void setMinimumWidth (int w )

通知程序信号:

void minimumWidthChanged (int arg )

modality : Qt::WindowModality

此特性保持窗口的模态

A modal window prevents other windows from receiving input events. Qt supports two types of modality: Qt::WindowModal and Qt::ApplicationModal .

默认情况下,此特性为 Qt::NonModal

访问函数:

Qt::WindowModality modality () const
void setModality (Qt::WindowModality modality )

通知程序信号:

void modalityChanged (Qt::WindowModality modality )

另请参阅 Qt::WindowModality .

opacity : qreal

此特性保持窗口系统中窗口的不透明度。

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.

默认值为 1.0。

访问函数:

qreal opacity () const
void setOpacity (qreal level )

通知程序信号:

void opacityChanged (qreal opacity )

title : QString

此特性保持窗口系统的窗口标题

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.

访问函数:

QString title () const
void setTitle (const QString &)

通知程序信号:

void windowTitleChanged (const QString & title )

另请参阅 flags ().

transientParent : QWindow *

此特性保持此窗口是瞬时弹出窗口

这是代表此窗口是瞬时父级对话框 (或弹出窗口) 的窗口管理器提示。

为促使窗口居中其瞬时 parent 默认情况下,从属窗口管理器,还可能有必要调用 setFlags () 采用合适 Qt::WindowType (譬如 Qt::Dialog ).

访问函数:

QWindow * transientParent () const
void setTransientParent (QWindow * parent )

通知程序信号:

void transientParentChanged (QWindow * transientParent )

另请参阅 parent ().

visibility : Visibility

此特性保持窗口的屏幕占用状态

Visibility is whether the window should appear in the windowing system as normal, minimized, maximized, fullscreen or hidden.

To set the visibility to AutomaticVisibility means to give the window a default visible state, which might be fullscreen or windowed depending on the platform. When reading the visibility property you will always get the actual state, never AutomaticVisibility .

访问函数:

QWindow::Visibility visibility () const
void setVisibility (QWindow::Visibility v )

通知程序信号:

void visibilityChanged (QWindow::Visibility visibility )

visible : bool

此特性保持窗口是否可见

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.

注意: Hiding a window does not remove the window from the windowing system, it only hides it. On windowing systems that give full screen applications a dedicated desktop (such as macOS), hiding a full screen window will not remove that desktop, but leave it blank. Another window from the same application might be shown full screen, and will fill that desktop. Use QWindow::close to completely remove a window from the windowing system.

访问函数:

bool isVisible () const
void setVisible (bool visible )

通知程序信号:

void visibleChanged (bool arg )

另请参阅 show ().

width : int

此特性保持窗口几何体的宽度

访问函数:

int width () const
void setWidth (int arg )

通知程序信号:

void widthChanged (int arg )

x : int

此特性保持窗口几何体的 X 位置

访问函数:

int x () const
void setX (int arg )

通知程序信号:

void xChanged (int arg )

y : int

此特性保持窗口几何体的 Y 位置

访问函数:

int y () const
void setY (int arg )

通知程序信号:

void yChanged (int arg )

成员函数文档编制

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

创建顶层窗口在 targetScreen .

窗口不展示直到 setVisible (true), show (),或调用类似的。

另请参阅 setScreen ().

[explicit] QWindow:: QWindow ( QWindow * parent )

创建窗口作为子级,为给定 parent 窗口。

窗口会被嵌入在父级窗口内,其坐标相对于父级。

屏幕继承自父级。

另请参阅 setParent ().

[virtual noexcept] QWindow:: ~QWindow ()

销毁窗口。

[slot] void QWindow:: alert ( int msec )

导致展示警报 msec 毫秒。若 msec is 0 (默认),则无限期展示警报,直到窗口再次变为活动为止。此函数对活动窗口不起作用。

在警报状态下,窗口指示 "要求关注",例如:通过刷新 (或弹跳) 任务栏条目。

QSize QWindow:: baseSize () const

返回窗口的基尺寸。

另请参阅 setBaseSize ().

[slot] bool QWindow:: close ()

关闭窗口。

这关闭窗口,高效调用 destroy (),且潜在离开应用程序。返回 true 当成功时,false 若它拥有父级窗口 (在这种情况下,取而代之应关闭顶层窗口)。

另请参阅 destroy (), QGuiApplication::quitOnLastWindowClosed (),和 closeEvent ().

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

覆写此以处理关闭事件 ( ev ).

函数被调用,当请求关闭窗口时。调用 QEvent::ignore () 在事件,若想要阻止窗口被关闭。

另请参阅 close ().

void QWindow:: create ()

分配窗口关联的平台资源。

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 () 被调用。

Note that it is not usually necessary to call this function directly, as it will be implicitly called by show (), setVisible (), winId (), and other functions that require access to the platform resources.

调用 destroy () 以释放平台资源,若有必要。

另请参阅 destroy ().

QCursor QWindow:: cursor () const

用于此窗口的光标形状

另请参阅 setCursor () 和 unsetCursor ().

void QWindow:: destroy ()

释放关联此窗口的本机平台资源。

另请参阅 create ().

qreal QWindow:: devicePixelRatio () const

Returns the ratio between physical pixels and device-independent pixels for the window. This value is dependent on the screen the window is on, and may change when the window is moved.

Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays.

注意: For windows not backed by a platform window, meaning that create () was not called, the function will fall back to the associated QScreen 的设备像素比率。

另请参阅 QScreen::devicePixelRatio ().

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

重实现: QObject::event (QEvent *e).

覆写此以处理任何事件 ( ev ) 被发送给窗口。返回 true 若事件被识别并处理。

记得调用基类版本,若希望如往常一样分派鼠标事件、键事件、重置大小事件、等。

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

暴露事件 ( ev ) 由窗口系统发送,当窗口在未暴露和暴露状态之间移动时。

暴露窗口对用户可能可见。若窗口被移出屏幕、被另一窗口完全遮盖、被最小化、或类似的,此函数可能被调用,且值 isExposed () 可能变为 false。可以使用此事件来限制昂贵操作,譬如:当窗口暴露时才运行的动画。

不应将此事件用于描绘。要处理描绘,实现 paintEvent () 代替。

重置大小事件将始终被发送,在暴露事件首次展示窗口之前。

另请参阅 paintEvent () 和 isExposed ().

QString QWindow:: filePath () const

表示此窗口的文件名。

另请参阅 setFilePath ().

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

覆写此以处理聚焦入事件 ( ev ).

发送聚焦入事件,当窗口接收键盘聚焦时。

另请参阅 focusOutEvent ().

[虚拟] QObject *QWindow:: focusObject () const

返回 QObject 将是聚焦捆绑事件 (譬如:键事件) 的最终接收者。

[signal] void QWindow:: focusObjectChanged ( QObject * object )

此信号被发射,当聚焦捆绑事件的最终接收者变为 object .

另请参阅 focusObject ().

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

覆写此以处理聚焦出事件 ( ev ).

发送聚焦出事件,当窗口失去键盘聚焦时。

另请参阅 focusInEvent ().

[override virtual] QSurfaceFormat QWindow:: format () const

重实现: QSurface::format() const .

返回此窗口的实际格式。

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. It might also be a superset, for example certain buffer sizes may be larger than requested.

注意: Depending on the platform, certain values in this surface format may still contain the requested values, that is, the values that have been passed to setFormat (). Typical examples are the OpenGL version, profile and options. These may not get updated during create () since these are context specific and a single window may be used together with multiple contexts over its lifetime. Use the QOpenGLContext 's format() instead to query such values.

另请参阅 setFormat (), create (), requestedFormat (),和 QOpenGLContext::format ().

QRect QWindow:: frameGeometry () const

返回窗口几何体,包括其窗口框架。

几何体与其屏幕 virtualGeometry() 相关。

另请参阅 geometry () 和 frameMargins ().

QMargins QWindow:: frameMargins () const

返回窗口周围的窗口框架边距。

另请参阅 geometry () 和 frameGeometry ().

QPoint QWindow:: framePosition () const

返回窗口的左上位置,包括其窗口框架。

这返回相同值如 frameGeometry ().topLeft().

另请参阅 setFramePosition (), geometry (),和 frameGeometry ().

[static] QWindow *QWindow:: fromWinId ( WId id )

创建由另一进程 (或由使用 Qt 下本机库) 创建的窗口的本地表示。

给定句柄 id 到本机窗口,此方法创建 QWindow 对象可以用于表示窗口,当援引方法像 setParent () 和 setTransientParent ().

这可以在支持它的平台中使用,以嵌入 QWindow 在本机窗口,或把本机窗口嵌入在 QWindow .

若外来窗口不被支持,或在平台插件中嵌入本机窗口失败,此函数返回 nullptr .

注意: 结果 QWindow 不应用于操纵底层本机窗口 (除重新父级化外),或用于观察本机窗口的状态变化。对这类操作的任何支持都是偶然的,高度依赖平台且未经测试。

另请参阅 setParent ().

QRect QWindow:: geometry () const

返回窗口几何体,不包括窗口框架。

几何体与其屏幕 virtualGeometry() 相关。

另请参阅 setGeometry (), frameMargins (),和 frameGeometry ().

[slot] void QWindow:: hide ()

隐藏窗口。

相当于调用 setVisible (false).

另请参阅 show () 和 setVisible ().

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

覆写此以处理隐藏事件 ( ev ).

函数被调用,当窗口请求在窗口系统中隐藏时。

QIcon QWindow:: icon () const

返回窗口系统中的窗口图标

另请参阅 setIcon ().

bool QWindow:: isActive () const

返回 true 若窗口是活动的。

对于拥有输入聚焦的窗口,及与聚焦窗口在同一父级/瞬时父级链中的窗口都如此。

通常,活动窗口从样式角度看上去应活动。

要获取目前有聚焦的窗口,使用 QGuiApplication::focusWindow ().

注意: getter 函数对于特性 active .

另请参阅 requestActivate ().

bool QWindow:: isAncestorOf (const QWindow * child , QWindow::AncestorMode mode = IncludeTransients) const

返回 true 若窗口是祖先对于给定 child 。若 mode is IncludeTransients ,则认为瞬时父级也是祖先。

bool QWindow:: isExposed () const

返回若此窗口暴露于窗口系统。

当未暴露时,窗口由应用程序展示,但尚未展示在窗口系统中,所以,应最小化动画应用程序及其它图形活动。

An exposeEvent () 被发送每当此值改变时。

另请参阅 exposeEvent ().

bool QWindow:: isModal () const

返回窗口是否是模态的。

模态窗口阻止其它窗口获取任何输入。

另请参阅 QWindow::modality .

bool QWindow:: isTopLevel () const

返回窗口是否在顶层 (即:没有父级窗口)。

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

覆写此以处理键按下事件 ( ev ).

另请参阅 keyReleaseEvent ().

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

覆写此以处理键释放事件 ( ev ).

另请参阅 keyPressEvent ().

[slot] void QWindow:: lower ()

降低窗口系统中的窗口。

请求降低窗口将出现在其它窗口下方。

[since 6.0] QPointF QWindow:: mapFromGlobal (const QPointF & pos ) const

翻译全局屏幕坐标 pos 到窗口坐标。

该函数在 Qt 6.0 引入。

另请参阅 mapToGlobal ().

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

这是重载函数。

[since 6.0] QPointF QWindow:: mapToGlobal (const QPointF & pos ) const

翻译窗口坐标 pos 到全局屏幕坐标。例如: mapToGlobal(QPointF(0,0)) 将给出窗口左上像素的全局坐标。

该函数在 Qt 6.0 引入。

另请参阅 mapFromGlobal ().

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

这是重载函数。

QRegion QWindow:: mask () const

返回窗口中设置的遮罩。

The mask is a hint to the windowing system that the application does not want to receive mouse or touch input outside the given region.

另请参阅 setMask ().

QSize QWindow:: maximumSize () const

返回窗口的最大尺寸。

另请参阅 setMaximumSize ().

QSize QWindow:: minimumSize () const

返回窗口的最小尺寸。

另请参阅 setMinimumSize ().

[signal] void QWindow:: modalityChanged ( Qt::WindowModality modality )

此信号被发射当 Qwindow::modality 特性变为 modality .

注意: 通知程序信号对于特性 modality .

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

覆写此以处理鼠标双击事件 ( ev ).

另请参阅 mousePressEvent () 和 QStyleHints::mouseDoubleClickInterval ().

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

覆写此以处理鼠标移动事件 ( ev ).

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

覆写此以处理鼠标按下事件 ( ev ).

另请参阅 mouseReleaseEvent ().

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

覆写此以处理鼠标释放事件 ( ev ).

另请参阅 mousePressEvent ().

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

覆写此以处理窗口移动事件 ( ev ).

[virtual protected] bool QWindow:: nativeEvent (const QByteArray & eventType , void * message , qintptr * result )

覆写此以处理平台从属事件。将给定 eventType , message and result .

这会使应用程序不可移植。

才应返回 true 若事件已处理。

[virtual protected, since 6.0] void QWindow:: paintEvent ( QPaintEvent * ev )

描绘事件 ( ev ) is sent by the window system whenever an area of the window needs a repaint, for example when initially showing the window, or due to parts of the window being uncovered by moving another window.

The application is expected to render into the window in response to the paint event, regardless of the exposed state of the window. For example, a paint event may be sent before the window is exposed, to prepare it for showing to the user.

该函数在 Qt 6.0 引入。

另请参阅 exposeEvent ().

QWindow *QWindow:: parent ( QWindow::AncestorMode mode = ExcludeTransients) const

返回父级窗口,若有的话。

mode is IncludeTransients ,则返回瞬时父级若没有父级。

没有父级的窗口称为顶层窗口。

另请参阅 setParent ().

QPoint QWindow:: position () const

返回排除任何窗口框架的桌面窗口位置

注意: 并非所有窗口系统都支持设置 (或查询) 顶层窗口位置。在这种系统,以编程方式移动窗口可能没有任何效果,且可能为当前位置返回人工值,譬如 QPoint(0, 0) .

另请参阅 setPosition ().

[slot] void QWindow:: raise ()

在窗口系统中提升窗口。

请求提升窗口将出现在其它窗口上方。

[slot] void QWindow:: requestActivate ()

请求激活窗口 (即:接收键盘聚焦)。

另请参阅 isActive () 和 QGuiApplication::focusWindow ().

[slot] void QWindow:: requestUpdate ()

调度 QEvent::UpdateRequest 事件以交付到此窗口。

The event is delivered in sync with the display vsync on platforms where this is possible. Otherwise, the event is delivered after a delay of at most 5 ms. If the window's associated screen reports a refresh rate higher than 60 Hz, the interval is scaled down to a value smaller than 5. The additional time is there to give the event loop a bit of idle time to gather system events, and can be overridden using the QT_QPA_UPDATE_IDLE_TIME environment variable.

When driving animations, this function should be called once after drawing has completed. Calling this function multiple times will result in a single event being delivered to the window.

子类化的 QWindow 应重实现 event (), intercept the event and call the application's rendering code, then call the base class implementation.

注意: The subclass' reimplementation of event () must invoke the base class implementation, unless it is absolutely sure that the event does not need to be handled by the base class. For example, the default implementation of this function relies on QEvent::Timer events. Filtering them away would therefore break the delivery of the update events.

QSurfaceFormat QWindow:: requestedFormat () const

返回此窗口请求的表面格式。

If the requested format was not supported by the platform implementation, the requestedFormat will differ from the actual window format.

此值的设置是采用 setFormat ().

另请参阅 setFormat () 和 format ().

void QWindow:: resize (const QSize & newSize )

将窗口 (不包括任何窗口框架) 大小设为 newSize

另请参阅 size () 和 geometry ().

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

将窗口 (不包括任何窗口框架) 大小设为 QSize 构造自宽度 w 和高度 h

对于交互重置窗口大小,见 startSystemResize ().

另请参阅 size () 和 geometry ().

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

覆写此以处理重置大小事件 ( ev ).

The resize event is called whenever the window is resized in the windowing system, either directly through the windowing system acknowledging a setGeometry () 或 resize () request, or indirectly through the user resizing the window manually.

QScreen *QWindow:: screen () const

返回在其中展示窗口的屏幕,或 null 若没有的话。

对于子级窗口,这返回相应顶层窗口屏幕。

另请参阅 setScreen () 和 QScreen::virtualSiblings ().

[signal] void QWindow:: screenChanged ( QScreen * screen )

此信号被发射当窗口的 screen 改变,通过明确设置采用 setScreen (),或自动当移除窗口屏幕时。

void QWindow:: setBaseSize (const QSize & size )

设置基 size 为窗口。

The base size is used to calculate a proper window size if the window defines sizeIncrement ().

另请参阅 setMinimumSize (), setMaximumSize (), setSizeIncrement (),和 baseSize ().

void QWindow:: setCursor (const QCursor & cursor )

设置用于此窗口的光标形状

鼠标 cursor will assume this shape when it is over this window, unless an override cursor is set. See the 预定义光标对象列表 了解有用形状范围。

If no cursor has been set, or after a call to unsetCursor (), the parent window's cursor is used.

By default, the cursor has the Qt::ArrowCursor 形状。

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 ().

另请参阅 cursor () 和 QGuiApplication::setOverrideCursor ().

void QWindow:: setFilePath (const QString & filePath )

set the file name this window is representing.

The windowing system might use filePath to display the path of the document this window is representing in the tile bar.

另请参阅 filePath ().

void QWindow:: setFlag ( Qt::WindowType flag , bool on = true)

设置窗口标志 flag on this window if on 为 true;否则清零标志。

另请参阅 setFlags (), flags (),和 type ().

void QWindow:: setFormat (const QSurfaceFormat & format )

Sets the window's surface format .

The format determines properties such as color depth, alpha, depth and stencil buffer size, etc. For example, to give a window a transparent background (provided that the window system supports compositing, and provided that other content in the window does not make it opaque again):

QSurfaceFormat format;
format.setAlphaBufferSize(8);
window.setFormat(format);
					

The surface format will be resolved in the create () function. Calling this function after create () has been called will not re-resolve the surface format of the native surface.

When the format is not explicitly set via this function, the format returned by QSurfaceFormat::defaultFormat () will be used. This means that when having multiple windows, individual calls to this function can be replaced by one single call to QSurfaceFormat::setDefaultFormat () before creating the first window.

另请参阅 format (), create (), destroy (),和 QSurfaceFormat::setDefaultFormat ().

void QWindow:: setFramePosition (const QPoint & point )

Sets the upper left position of the window ( point ) including its window frame.

位置与其屏幕的 virtualGeometry() 有关。

另请参阅 framePosition (), setGeometry (),和 frameGeometry ().

[slot] void QWindow:: setGeometry ( int posx , int posy , int w , int h )

将窗口几何体 (不包括窗口框架) 设为矩形构造自 posx , posy , w and h .

几何体与其屏幕 virtualGeometry() 相关。

另请参阅 geometry ().

[slot] void QWindow:: setGeometry (const QRect & rect )

将窗口几何体 (不包括窗口框架) 设为 rect .

几何体与其屏幕 virtualGeometry() 相关。

另请参阅 geometry ().

void QWindow:: setIcon (const QIcon & icon )

设置窗口 icon in the windowing system

The window icon might be used by the windowing system for example to decorate the window, and/or in the task switcher.

注意: On macOS, the window title bar icon is meant for windows representing documents, and will only show up if a file path is also set.

另请参阅 icon () 和 setFilePath ().

bool QWindow:: setKeyboardGrabEnabled ( bool grab )

Sets whether keyboard grab should be enabled or not ( grab ).

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 () 若想要抓取这。

另请参阅 setMouseGrabEnabled ().

void QWindow:: setMask (const QRegion & region )

Sets the mask of the window.

The mask is a hint to the windowing system that the application does not want to receive mouse or touch input outside the given region .

The window manager may or may not choose to display any areas of the window not included in the mask, thus it is the application's responsibility to clear to transparent the areas that are not part of the mask.

另请参阅 mask ().

void QWindow:: setMaximumSize (const QSize & size )

Sets the maximum size of the window.

This is a hint to the window manager to prevent resizing above the specified size .

另请参阅 setMinimumSize () 和 maximumSize ().

void QWindow:: setMinimumSize (const QSize & size )

Sets the minimum size of the window.

This is a hint to the window manager to prevent resizing below the specified size .

另请参阅 setMaximumSize () 和 minimumSize ().

bool QWindow:: setMouseGrabEnabled ( bool grab )

Sets whether mouse grab should be enabled or not ( grab ).

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 () 若想要抓取这。

另请参阅 setKeyboardGrabEnabled ().

void QWindow:: setParent ( QWindow * parent )

设置 parent 窗口。这将导致窗口系统管理窗口的裁剪,因此,它将被裁剪到 parent 窗口。

设置 parent nullptr 将使窗口变为顶层窗口。

parent 是窗口创建通过 fromWinId (),那么当前窗口将被嵌入在 parent ,若平台支持它。

另请参阅 parent ().

void QWindow:: setPosition (const QPoint & pt )

把窗口在桌面上的位置,设为 pt

位置与其屏幕的 virtualGeometry() 有关。

对于交互移动窗口,见 startSystemMove (). For interactively resizing windows, see startSystemResize ().

注意: 并非所有窗口系统都支持设置 (或查询) 顶层窗口位置。在这种系统,以编程方式移动窗口可能没有任何效果,且可能为当前位置返回人工值,譬如 QPoint(0, 0) .

另请参阅 position () 和 startSystemMove ().

void QWindow:: setPosition ( int posx , int posy )

把窗口在桌面上的位置,设为 posx , posy

位置与其屏幕的 virtualGeometry() 有关。

另请参阅 position ().

void QWindow:: setScreen ( QScreen * newScreen )

Sets the screen on which the window should be shown.

If the window has been created, it will be recreated on the newScreen .

注意: 若屏幕是多屏幕虚拟桌面的一部分,窗口不会自动移至 newScreen 。要相对屏幕放置窗口,使用屏幕的 topLeft() 位置。

This function only works for top level windows.

另请参阅 screen () 和 QScreen::virtualSiblings ().

void QWindow:: setSizeIncrement (const QSize & size )

设置尺寸增量 ( size ) 为窗口。

When the user resizes the window, the size will move in steps of sizeIncrement (). width () pixels horizontally and sizeIncrement (). height () 像素垂直,采用 baseSize () as the basis.

默认情况下,此特性包含 0 大小宽度和高度。

窗口系统可能不支持大小增量。

另请参阅 sizeIncrement (), setBaseSize (), setMinimumSize (),和 setMaximumSize ().

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

设置 surfaceType 为窗口。

指定窗口为光栅渲染采用 QBackingStore ,或 OpenGL 渲染采用 QOpenGLContext .

The surfaceType will be used when the native surface is created in the create () function. Calling this function after the native surface has been created requires calling destroy () 和 create () to release the old native surface and create a new one.

另请参阅 surfaceType (), QBackingStore , QOpenGLContext , create (),和 destroy ().

void QWindow:: setVulkanInstance ( QVulkanInstance * 实例 )

将此窗口关联到指定 Vulkan 实例 .

实例 must stay valid as long as this QWindow instance exists.

另请参阅 vulkanInstance ().

void QWindow:: setWindowState ( Qt::WindowState state )

设置窗口的屏幕占用状态

窗口 state represents whether the window appears in the windowing system as maximized, minimized, fullscreen, or normal.

枚举值 Qt::WindowActive 不是可接受参数。

另请参阅 windowState (), showNormal (), showFullScreen (), showMinimized (), showMaximized (),和 setWindowStates ().

void QWindow:: setWindowStates ( Qt::WindowStates state )

设置窗口的屏幕占用状态

窗口 state represents whether the window appears in the windowing system as maximized, minimized and/or fullscreen.

The window can be in a combination of several states. For example, if the window is both minimized and maximized, the window will appear minimized, but clicking on the task bar entry will restore it to the maximized state.

枚举值 Qt::WindowActive 不应该设置。

另请参阅 windowStates (), showNormal (), showFullScreen (), showMinimized (),和 showMaximized ().

[slot] void QWindow:: show ()

展示窗口。

对于子级窗口,这相当于调用 showNormal (). Otherwise, it is equivalent to calling showFullScreen (), showMaximized (),或 showNormal (), depending on the platform's default behavior for the window type and flags.

另请参阅 showFullScreen (), showMaximized (), showNormal (), hide (), QStyleHints::showIsFullScreen (),和 flags ().

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

覆写此以处理展示事件 ( ev ).

调用函数,当窗口请求变为可见时。

If the window is successfully shown by the windowing system, this will be followed by a resize and an expose event.

[slot] void QWindow:: showFullScreen ()

以全屏方式展示窗口。

相当于调用 setWindowStates ( Qt::WindowFullScreen ) 然后 setVisible (true)。

QWidget::showFullScreen () 文档编制了解特定平台注意事项和局限性。

另请参阅 setWindowStates () 和 setVisible ().

[slot] void QWindow:: showMaximized ()

按最大化方式展示窗口。

相当于调用 setWindowStates ( Qt::WindowMaximized ) 然后 setVisible (true)。

另请参阅 setWindowStates () 和 setVisible ().

[slot] void QWindow:: showMinimized ()

按最小化方式展示窗口。

相当于调用 setWindowStates ( Qt::WindowMinimized ) 然后 setVisible (true)。

另请参阅 setWindowStates () 和 setVisible ().

[slot] void QWindow:: showNormal ()

按正常方式 (即:最大化、最小化、或全屏) 展示窗口。

相当于调用 setWindowStates ( Qt::WindowNoState ) 然后 setVisible (true)。

另请参阅 setWindowStates () 和 setVisible ().

[override virtual] QSize QWindow:: size () const

重实现: QSurface::size() const .

返回不包括任何窗口框架的窗口大小

另请参阅 resize ().

QSize QWindow:: sizeIncrement () const

返回窗口的大小增量。

另请参阅 setSizeIncrement ().

[slot] bool QWindow:: startSystemMove ()

启动系统特定移动操作

Calling this will start an interactive move operation on the window by platforms that support it. The actual behavior may vary depending on the platform. Usually, it will make the window follow the mouse cursor until a mouse button is released.

On platforms that support it, this method of moving windows is preferred over setPosition , because it allows a more native look-and-feel of moving windows, e.g. letting the window manager snap this window against other windows, or special tiling or resizing behavior with animations when dragged to the edge of the screen. Furthermore, on some platforms such as Wayland, setPosition is not supported, so this is the only way the application can influence its position.

返回 true 若系统支持操作。

[slot] bool QWindow:: startSystemResize ( Qt::Edges edges )

启动系统特定重置大小操作

Calling this will start an interactive resize operation on the window by platforms that support it. The actual behavior may vary depending on the platform. Usually, it will make the window resize so that its edge follows the mouse cursor.

On platforms that support it, this method of resizing windows is preferred over setGeometry , because it allows a more native look and feel of resizing windows, e.g. letting the window manager snap this window against other windows, or special resizing behavior with animations when dragged to the edge of the screen.

edges should either be a single edge, or two adjacent edges (a corner). Other values are not allowed.

返回 true 若系统支持操作。

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

重实现: QSurface::surfaceType() const .

返回窗口的表面类型。

另请参阅 setSurfaceType ().

[virtual protected] void QWindow:: tabletEvent ( QTabletEvent * ev )

覆写此以处理数位板按下、移动、及释放事件 ( ev ).

接近进入和离开事件不会发送给窗口,它们会被交付给应用程序实例。

[virtual protected] void QWindow:: touchEvent ( QTouchEvent * ev )

覆写此以处理触摸事件 ( ev ).

Qt::WindowType QWindow:: type () const

返回窗口的类型。

这返回表示窗口是否为对话框、工具提示、弹出窗口、常规窗口、等的窗口标志部分。

另请参阅 flags () 和 setFlags ().

void QWindow:: unsetCursor ()

还原用于此窗口的默认箭头光标。

QVulkanInstance *QWindow:: vulkanInstance () const

返回关联的 Vulkan 实例若有设置,否则 nullptr .

另请参阅 setVulkanInstance ().

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

覆写此以处理鼠标滚轮或其它滚轮事件 ( ev ).

WId QWindow:: winId () const

返回窗口的平台 ID。

注意: This function will cause the platform window to be created if it is not already. Returns 0, if the platform window creation failed.

对于此 ID 可能有用的平台,返回值将表示相应屏幕内的唯一窗口。

另请参阅 screen ().

Qt::WindowState QWindow:: windowState () const

窗口的屏幕占用状态

另请参阅 setWindowState () 和 windowStates ().

[signal] void QWindow:: windowStateChanged ( Qt::WindowState windowState )

此信号发射当 windowState 改变,通过明确设置采用 setWindowStates (),或自动当用户点击标题栏按钮之一或通过其它方式。

Qt::WindowStates QWindow:: windowStates () const

窗口的屏幕占用状态

The window can be in a combination of several states. For example, if the window is both minimized and maximized, the window will appear minimized, but clicking on the task bar entry will restore it to the maximized state.

另请参阅 setWindowStates ().