QQuickWindow 類提供用於顯示圖形 QML 場景的窗口。 更多...
| 頭: | #include <QQuickWindow> |
| qmake: | QT += quick |
| Since: | Qt 5.0 |
| 實例化: | Window |
| 繼承: | QWindow |
| 繼承者: |
該類在 Qt 5.0 引入。
| struct | GraphicsStateInfo |
| enum | CreateTextureOption { TextureHasAlphaChannel, TextureHasMipmaps, TextureOwnsGLTexture, TextureCanUseAtlas, TextureIsOpaque } |
| flags | CreateTextureOptions |
| enum | NativeObjectType { NativeObjectTexture } |
| enum | RenderStage { BeforeSynchronizingStage, AfterSynchronizingStage, BeforeRenderingStage, AfterRenderingStage, AfterSwapStage, NoStage } |
| enum | SceneGraphError { ContextNotAvailable } |
| enum | TextRenderType { QtTextRendering, NativeTextRendering } |
| QQuickWindow (QQuickRenderControl * control ) | |
| QQuickWindow (QWindow * parent = nullptr) | |
| virtual | ~QQuickWindow () override |
| QQuickItem * | activeFocusItem () const |
| void | beginExternalCommands () |
| bool | clearBeforeRendering () const |
| QColor | color () const |
| QQuickItem * | contentItem () const |
| QSGImageNode * | createImageNode () const |
| QSGNinePatchNode * | createNinePatchNode () const |
| QSGRectangleNode * | createRectangleNode () const |
| QSGTexture * | createTextureFromImage (const QImage & image , QQuickWindow::CreateTextureOptions options ) const |
| QSGTexture * | createTextureFromImage (const QImage & image ) const |
| QSGTexture * | createTextureFromNativeObject (QQuickWindow::NativeObjectType type , const void * nativeObjectPtr , int nativeLayout , const QSize & size , QQuickWindow::CreateTextureOptions options = CreateTextureOption()) const |
| qreal | effectiveDevicePixelRatio () const |
| void | endExternalCommands () |
| QImage | grabWindow () |
| const QQuickWindow::GraphicsStateInfo & | graphicsStateInfo () |
| QQmlIncubationController * | incubationController () const |
| bool | isPersistentOpenGLContext () const |
| bool | isPersistentSceneGraph () const |
| bool | isSceneGraphInitialized () const |
| QQuickItem * | mouseGrabberItem () const |
| QOpenGLContext * | openglContext () const |
| QOpenGLFramebufferObject * | renderTarget () const |
| uint | renderTargetId () const |
| QSize | renderTargetSize () const |
| QSGRendererInterface * | rendererInterface () const |
| void | resetOpenGLState () |
| void | scheduleRenderJob (QRunnable * job , QQuickWindow::RenderStage stage ) |
| void | setClearBeforeRendering (bool enabled ) |
| void | setColor (const QColor & color ) |
| void | setPersistentOpenGLContext (bool persistent ) |
| void | setPersistentSceneGraph (bool persistent ) |
| void | setRenderTarget (QOpenGLFramebufferObject * fbo ) |
| void | setRenderTarget (uint fboId , const QSize & size ) |
| virtual QAccessibleInterface * | accessibleRoot () const override |
| void | releaseResources () |
| void | update () |
| void | activeFocusItemChanged () |
| void | afterAnimating () |
| void | afterRenderPassRecording () |
| void | afterRendering () |
| void | afterSynchronizing () |
| void | beforeRenderPassRecording () |
| void | beforeRendering () |
| void | beforeSynchronizing () |
| void | closing (QQuickCloseEvent * close ) |
| void | colorChanged ( const QColor & ) |
| void | frameSwapped () |
| void | openglContextCreated (QOpenGLContext * context ) |
| void | sceneGraphAboutToStop () |
| void | sceneGraphError (QQuickWindow::SceneGraphError error , const QString & message ) |
| void | sceneGraphInitialized () |
| void | sceneGraphInvalidated () |
| bool | hasDefaultAlphaBuffer () |
| QString | sceneGraphBackend () |
| void | setDefaultAlphaBuffer (bool useAlpha ) |
| void | setSceneGraphBackend (QSGRendererInterface::GraphicsApi api ) |
| void | setSceneGraphBackend (const QString & backend ) |
| void | setTextRenderType (QQuickWindow::TextRenderType renderType ) |
| QQuickWindow::TextRenderType | textRenderType () |
| virtual bool | event (QEvent * e ) override |
| virtual void | exposeEvent ( QExposeEvent * ) override |
| virtual void | focusInEvent (QFocusEvent * ev ) override |
| virtual void | focusOutEvent (QFocusEvent * ev ) override |
| virtual void | hideEvent ( QHideEvent * ) override |
| virtual void | keyPressEvent (QKeyEvent * e ) override |
| virtual void | keyReleaseEvent (QKeyEvent * e ) override |
| virtual void | mouseDoubleClickEvent (QMouseEvent * event ) override |
| virtual void | mouseMoveEvent (QMouseEvent * event ) override |
| virtual void | mousePressEvent (QMouseEvent * event ) override |
| virtual void | mouseReleaseEvent (QMouseEvent * event ) override |
| virtual void | resizeEvent (QResizeEvent * ev ) override |
| virtual void | showEvent ( QShowEvent * ) override |
| virtual void | tabletEvent (QTabletEvent * event ) override |
| virtual void | wheelEvent (QWheelEvent * event ) override |
QQuickWindow 提供與 QQuickItems 場景交互和顯示,所需的圖形場景管理。
QQuickWindow 始終擁有單個不可見根項。要把項添加到此窗口,將項錶示成根項 (或場景中的現有項)。
為輕鬆從 QML 文件顯示場景,見 QQuickView .
QQuickWindow uses a scene graph to represent what needs to be rendered. This scene graph is disconnected from the QML scene and potentially lives in another thread, depending on the platform implementation. Since the rendering scene graph lives independently from the QML scene, it can also be completely released without affecting the state of the QML scene.
The sceneGraphInitialized () signal is emitted on the rendering thread before the QML scene is rendered to the screen for the first time. If the rendering scene graph has been released, the signal will be emitted again before the next frame is rendered.
When using the default OpenGL adaptation, it is possible to integrate OpenGL calls directly into the QQuickWindow using the same OpenGL context as the Qt Quick Scene Graph. This is done by connecting to the QQuickWindow::beforeRendering () 或 QQuickWindow::afterRendering () 信號。
注意: 當使用 QQuickWindow::beforeRendering (), make sure to disable clearing before rendering with QQuickWindow::setClearBeforeRendering ().
When a QQuickWindow instance is deliberately hidden with hide () 或 setVisible (false), it will stop rendering and its scene graph and graphics context might be released. The sceneGraphInvalidated () signal will be emitted when this happens.
警告: It is crucial that graphics operations and interaction with the scene graph happens exclusively on the rendering thread, primarily during the updatePaintNode() phase.
警告: As signals related to rendering might be emitted from the rendering thread, connections should be made using Qt::DirectConnection .
QML will try to cache images and scene graph nodes to improve performance, but in some low-memory scenarios it might be required to aggressively release these resources. The releaseResources () can be used to force the clean up of certain resources. Calling releaseResources () may result in the entire scene graph and in the case of the OpenGL adaptation the associated context will be deleted. The sceneGraphInvalidated () signal will be emitted when this happens.
注意: 所有帶有 QSG 前綴的類隻應用於場景圖形渲染綫程。見 場景圖形和渲染 瞭解更多信息。
While it is possible to specify a QSurfaceFormat for every QQuickWindow by calling the member function setFormat (), windows may also be created from QML by using the Window and ApplicationWindow elements. In this case there is no C++ code involved in the creation of the window instance, yet applications may still wish to set certain surface format values, for example to request a given OpenGL version or profile. Such applications can call the static function QSurfaceFormat::setDefaultFormat () at startup. The specified format will be used for all Quick windows created afterwards.
另請參閱 場景圖形 - QML 下的 OpenGL .
The CreateTextureOption enums are used to customize a texture is wrapped.
| 常量 | 值 | 描述 |
|---|---|---|
QQuickWindow::TextureHasAlphaChannel
|
0x0001
|
The texture has an alpha channel and should be drawn using blending. |
QQuickWindow::TextureHasMipmaps
|
0x0002
|
The texture has mipmaps and can be drawn with mipmapping enabled. |
QQuickWindow::TextureOwnsGLTexture
|
0x0004
|
The texture object owns the texture id and will delete the OpenGL texture when the texture object is deleted. |
QQuickWindow::TextureCanUseAtlas
|
0x0008
|
The image can be uploaded into a texture atlas. |
QQuickWindow::TextureIsOpaque
|
0x0010
|
The texture will return false for QSGTexture::hasAlphaChannel () and will not be blended. This flag was added in Qt 5.6. |
CreateTextureOptions 類型是 typedef 對於 QFlags <CreateTextureOption>. It stores an OR combination of CreateTextureOption values.
Specifies the type of the native object passed to functions such as createTextureFromNativeObject ().
| 常量 | 值 | 描述 |
|---|---|---|
QQuickWindow::NativeObjectTexture
|
0
|
The native object is a 2D texture (OpenGL, Direct3D 11, Metal) or image (Vulkan). |
該枚舉在 Qt 5.14 引入或被修改。
| 常量 | 值 | 描述 |
|---|---|---|
QQuickWindow::BeforeSynchronizingStage
|
0
|
在同步前。 |
QQuickWindow::AfterSynchronizingStage
|
1
|
在同步後。 |
QQuickWindow::BeforeRenderingStage
|
2
|
在渲染前。 |
QQuickWindow::AfterRenderingStage
|
3
|
在渲染後。 |
QQuickWindow::AfterSwapStage
|
4
|
在幀交換後。 |
QQuickWindow::NoStage
|
5
|
盡快。該值在 Qt 5.6 添加。 |
該枚舉在 Qt 5.4 引入或被修改。
另請參閱 場景圖形和渲染 .
此枚舉描述的錯誤在 sceneGraphError () 信號。
| 常量 | 值 | 描述 |
|---|---|---|
QQuickWindow::ContextNotAvailable
|
1
|
graphics context creation failed. This typically means that no suitable OpenGL implementation was found, for example because no graphics drivers are installed and so no OpenGL 2 support is present. On mobile and embedded boards that use OpenGL ES such an error is likely to indicate issues in the windowing system integration and possibly an incorrect configuration of Qt. |
該枚舉在 Qt 5.3 引入或被修改。
此枚舉描述 Qt Quick 中像文本元素的默認渲染類型 ( Text , TextInput ,等)。
Select NativeTextRendering if you prefer text to look native on the target platform and do not require advanced features such as transformation of the text. Using such features in combination with the NativeTextRendering render type will lend poor and sometimes pixelated results.
| 常量 | 值 | 描述 |
|---|---|---|
QQuickWindow::QtTextRendering
|
0
|
使用 Qt 自己的光柵化算法。 |
QQuickWindow::NativeTextRendering
|
1
|
對文本使用 OS (操作係統) 的本機光柵化器。 |
該枚舉在 Qt 5.10 引入或被修改。
此特性保持的項目前擁有活動聚焦或
null
若沒有項具有活動聚焦。
訪問函數:
| QQuickItem * | activeFocusItem () const |
通知程序信號:
| void | activeFocusItemChanged () |
另請參閱 QQuickItem::forceActiveFocus () 和 Qt Quick 中的鍵盤聚焦 .
此特性保持用於清零 OpenGL 上下文的顔色。
設置清零顔色不起作用,當清零被禁用時。默認情況下,清零顔色為白色。
訪問函數:
| QColor | color () const |
| void | setColor (const QColor & color ) |
通知程序信號:
| void | colorChanged ( const QColor & ) |
另請參閱 setClearBeforeRendering () 和 setDefaultAlphaBuffer ().
此特性保持場景的不可見根項。
A QQuickWindow always has a single invisible root item containing all of its content. To add items to this window, reparent the items to the contentItem or to an existing item in the scene.
訪問函數:
| QQuickItem * | contentItem () const |
構造窗口為顯示 QML 場景,渲染的控製是通過 control 對象。請參考 QQuickRenderControl 文檔編製瞭解更多信息。
該函數在 Qt 5.4 引入。
構造窗口為顯示 QML 場景采用父級窗口 parent .
[signal]
void
QQuickWindow::
afterAnimating
()
此信號在 GUI 綫程中發射,在請求渲染綫程以履行場景圖形的同步前。
Unlike the other similar signals, this one is emitted on the GUI thread instead of the render thread. It can be used to synchronize external animation systems with the QML content. At the same time this means that this signal is not suitable for triggering graphics operations.
該函數在 Qt 5.3 引入。
[signal]
void
QQuickWindow::
afterRenderPassRecording
()
This signal is emitted after the scenegraph has recorded the commands for its main render pass, but the pass is not yet finalized on the command buffer.
This signal is applicable when using the RHI graphics abstraction with the scenegraph. It is emitted earlier than afterRendering () and it guarantees that not just the frame, but also the recording of the scenegraph's main render pass is still active. This allows inserting commands without having to generate an entire, separate render pass (which would typically clear the attached images). The native graphics objects can be queried via QSGRendererInterface .
When not running with the RHI (and using OpenGL directly), the signal is emitted after the renderer has finished its rendering, but before afterRendering (). This makes it possible to create applications that function identically both with and without the RHI.
注意: Resource updates (uploads, copies) typically cannot be enqueued from within a render pass. Therefore, more complex user rendering will need to connect to both beforeRendering () 和此信號。
警告: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType ).
該函數在 Qt 5.14 引入。
[signal]
void
QQuickWindow::
afterRendering
()
此信號在場景已完成渲染後發射,在 swapbuffers 被調用前。
此信號可以用於在 QML 內容上使用原生 OpenGL 進行描繪,或對當前幀緩衝做屏幕抓取。
用於渲染場景圖形的 OpenGL 上下文,會被綁定在此點。
When using the RHI, the signal is emitted after scene graph has added its commands to the command buffer, which is not yet submitted to the graphics queue. If desired, the slot function connected to this signal can query native resources, like the command buffer, before via QSGRendererInterface . Note however that the render pass (or passes) are already recorded at this point and it is not possible to add more commands within the scenegraph's pass. Instead, use afterRenderPassRecording () for that. This signal has therefore limited use and is rarely needed in an RHI-based setup. Rather, it is the combination of beforeRendering () + beforeRenderPassRecording () 或 beforeRendering () + afterRenderPassRecording () that is typically used to achieve under- or overlaying of the custom rendering.
警告: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType ).
警告: Make very sure that a signal handler for afterRendering() leaves the OpenGL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.
另請參閱 resetOpenGLState ().
[signal]
void
QQuickWindow::
afterSynchronizing
()
此信號發射,在同步場景圖形與 QML 狀態後。
This signal can be used to do preparation required after calls to QQuickItem::updatePaintNode (), while the GUI thread is still locked.
用於渲染場景圖形的圖形上下文,會被綁定在此點。
警告: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType ).
警告: When using the OpenGL adaptation, make sure that a signal handler for afterSynchronizing leaves the OpenGL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.
該函數在 Qt 5.3 引入。
另請參閱 resetOpenGLState ().
[signal]
void
QQuickWindow::
beforeRenderPassRecording
()
This signal is emitted before the scenegraph starts recording commands for the main render pass. (Layers have their own passes and are fully recorded by the time this signal is emitted.) The render pass is already active on the command buffer when the signal is emitted.
This signal is applicable when using the RHI graphics abstraction with the scenegraph. It is emitted later than beforeRendering () and it guarantees that not just the frame, but also the recording of the scenegraph's main render pass is active. This allows inserting commands without having to generate an entire, separate render pass (which would typically clear the attached images). The native graphics objects can be queried via QSGRendererInterface .
When not running with the RHI (and using OpenGL directly), the signal is emitted after the renderer has cleared the render target. This makes it possible to create applications that function identically both with and without the RHI.
注意: Resource updates (uploads, copies) typically cannot be enqueued from within a render pass. Therefore, more complex user rendering will need to connect to both beforeRendering () 和此信號。
警告: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType ).
該函數在 Qt 5.14 引入。
[signal]
void
QQuickWindow::
beforeRendering
()
此信號發射,在開始渲染場景前。
Combined with the modes for clearing the background, this option can be used to paint using raw OpenGL under QML content.
用於渲染場景圖形的 OpenGL 上下文,會被綁定在此點。
When using the RHI, the signal is emitted after the preparations for the frame have been done, meaning there is a command buffer in recording mode, where applicable. If desired, the slot function connected to this signal can query native resources like the command before via QSGRendererInterface . Note however that the recording of the main render pass is not yet started at this point and it is not possible to add commands within that pass. Starting a pass means clearing the color, depth, and stencil buffers so it is not possible to achieve an underlay type of rendering by just connecting to this signal. Rather, connect to beforeRenderPassRecording (). However, connecting to this signal is still important if the recording of copy type of commands is desired since those cannot be enqueued within a render pass.
警告: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType ).
警告: Make very sure that a signal handler for beforeRendering leaves the OpenGL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.
另請參閱 resetOpenGLState ().
[signal]
void
QQuickWindow::
beforeSynchronizing
()
This signal is emitted before the scene graph is synchronized with the QML state.
This signal can be used to do any preparation required before calls to QQuickItem::updatePaintNode ().
用於渲染場景圖形的 OpenGL 上下文,會被綁定在此點。
警告: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType ).
警告: Make very sure that a signal handler for beforeSynchronizing leaves the GL context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.
另請參閱 resetOpenGLState ().
[signal]
void
QQuickWindow::
closing
(
QQuickCloseEvent
*
close
)
此信號被發,當窗口收到事件 close 從窗口係統。
在 macOS,Qt 將創建菜單項
Quit
若不存在文本為 quit 或 exit 的菜單項。此菜單項調用
QCoreApplication::quit
信號,不是
QQuickWindow::closing()
信號。
該函數在 Qt 5.1 引入。
另請參閱 QMenuBar 作為全局菜單欄 .
[signal]
void
QQuickWindow::
frameSwapped
()
This signal is emitted when a frame has been queued for presenting. With vertical synchronization enabled the signal is emitted at most once per vsync interval in a continuously animating scene.
此信號將從場景圖形渲染綫程中發射。
[signal]
void
QQuickWindow::
openglContextCreated
(
QOpenGLContext
*
context
)
此信號在 GUI 綫程中發射,當 OpenGL context 對於此窗口有創建,在它變為當前前。
某些實現會共享同一 OpenGL 上下文介於多個 QQuickWindow instances. The openglContextCreated() signal will in this case only be emitted for the first window, when the OpenGL context is actually created.
QQuickWindow::openglContext () 將仍然返迴 0 對此窗口直到之後 QQuickWindow::sceneGraphInitialized () 已發射。
注意: This signal will only be emmited when using the default OpenGL scene graph adaptation.
該函數在 Qt 5.3 引入。
[slot]
void
QQuickWindow::
releaseResources
()
此函數會試著釋放目前由 QML 場景保持的冗餘資源。
Calling this function might result in the scene graph and the OpenGL context used for rendering being released to release graphics memory. If this happens, the sceneGraphInvalidated () signal will be called, allowing users to clean up their own graphics resources. The setPersistentOpenGLContext () 和 setPersistentSceneGraph () functions can be used to prevent this from happening, if handling the cleanup is not feasible in the application, at the cost of higher memory usage.
另請參閱 sceneGraphInvalidated (), setPersistentOpenGLContext (),和 setPersistentSceneGraph ().
[signal]
void
QQuickWindow::
sceneGraphAboutToStop
()
This signal is emitted on the render thread when the scene graph is about to stop rendering. This happens usually because the window has been hidden.
Applications may use this signal to release resources, but should be prepared to reinstantiated them again fast. The scene graph and the graphics context are not released at this time.
警告: This signal is emitted from the scene graph rendering thread. If your slot function needs to finish before execution continues, you must make sure that the connection is direct (see Qt::ConnectionType ).
警告: Make very sure that a signal handler for sceneGraphAboutToStop() leaves the graphics context in the same state as it was when the signal handler was entered. Failing to do so can result in the scene not rendering properly.
該函數在 Qt 5.3 引入。
另請參閱 sceneGraphInvalidated () 和 resetOpenGLState ().
[signal]
void
QQuickWindow::
sceneGraphError
(
QQuickWindow::SceneGraphError
error
, const
QString
&
message
)
此信號發射,當 error 齣現在場景圖形初始化期間。
Applications should connect to this signal if they wish to handle errors, like graphics context creation failures, in a custom way. When no slot is connected to the signal, the behavior will be different: Quick will print the message , or show a message box, and terminate the application.
此信號將從 GUI 綫程中發射。
該函數在 Qt 5.3 引入。
[signal]
void
QQuickWindow::
sceneGraphInitialized
()
此信號被發射,當場景圖形已初始化。
此信號將從場景圖形渲染綫程中發射。
[signal]
void
QQuickWindow::
sceneGraphInvalidated
()
此信號被發射,當場景圖形已無效。
This signal implies that the graphics rendering context used has been invalidated and all user resources tied to that context should be released.
In the case of the default OpenGL adaptation the context of this window will be bound when this function is called. The only exception is if the native OpenGL has been destroyed outside Qt's control, for instance through EGL_CONTEXT_LOST.
此信號將從場景圖形渲染綫程中發射。
[slot]
void
QQuickWindow::
update
()
調度窗口以渲染另一幀。
調用 QQuickWindow::update() 不同於 QQuickItem::update () in that it always triggers a repaint, regardless of changes in the underlying scene graph or not.
[override virtual]
QQuickWindow::
~QQuickWindow
()
銷毀窗口。
[override virtual]
QAccessibleInterface
*QQuickWindow::
accessibleRoot
() const
返迴此窗口的可訪問接口,或 0 若無法創建這種接口。
When mixing raw graphics (OpenGL, Vulkan, Metal, etc.) commands with scene graph rendering, it is necessary to call this function before recording commands to the command buffer used by the scene graph to render its main render pass. This is to avoid clobbering state.
在實踐中,此函數的調用經常是從槽連接到 beforeRenderPassRecording () 或 afterRenderPassRecording () 信號。
The function does not need to be called when recording commands to the application's own command buffer (such as, a VkCommandBuffer or MTLCommandBuffer + MTLRenderCommandEncoder created and managed by the application, not retrieved from the scene graph). With graphics APIs where no native command buffer concept is exposed (OpenGL, Direct 3D 11), beginExternalCommands() and endExternalCommands () together provide a replacement for resetOpenGLState ().
調用此函數和 endExternalCommands () 沒有必要在 render() 實現為 QSGRenderNode 因為場景圖形會為渲染節點,隱式履行必要步驟。
Native graphics objects (such as, graphics device, command buffer or encoder) are accessible via QSGRendererInterface::getResource ().
警告: Watch out for the fact that QSGRendererInterface::CommandListResource may return a different object between beginExternalCommands() - endExternalCommands (). This can happen when the underlying implementation provides a dedicated secondary command buffer for recording external graphics commands within a render pass. Therefore, always query CommandListResource after calling this function. Do not attempt to reuse an object from an earlier query.
注意: This function has no effect when the scene graph is using OpenGL directly and the RHI graphics abstraction layer is not in use. Refer to resetOpenGLState () in that case.
注意: When the scenegraph is using the RHI graphics abstraction layer with the OpenGL backend underneath, pay attention to the fact that the OpenGL state in the context can have arbitrary settings, and this function does not perform any resetting of the state back to defaults. Call resetOpenGLState () if that is seen necessary.
該函數在 Qt 5.14 引入。
另請參閱 endExternalCommands () 和 resetOpenGLState ().
返迴是否做做顔色緩衝清零,在渲染前。
另請參閱 setClearBeforeRendering ().
創建簡單圖像節點。當場景圖形未初始化時,返迴值為 null。
這是直接構造 QSGSimpleTextureNode 的跨後端替代。
該函數在 Qt 5.8 引入。
另請參閱 QSGImageNode .
創建 9 個補丁節點。當場景圖形未初始化時,返迴值為 null。
該函數在 Qt 5.8 引入。
創建簡單矩形節點。當場景圖形未初始化時,返迴值為 null。
這是直接構造 QSGSimpleRectNode 的跨後端替代。
該函數在 Qt 5.8 引入。
另請參閱 QSGRectangleNode .
創建新的 QSGTexture 從供給 image 。若圖像擁有 Alpha 通道,相應紋理將擁有 Alpha 通道。
函數的調用者負責刪除返迴紋理。例如,會刪除使用 OpenGL 適配的實際 OpenGL 紋理,當刪除紋理對象時。
當 options 包含 TextureCanUseAtlas ,引擎可以將圖像放入紋理圖集。圖集中的紋理需要依賴 QSGTexture::normalizedTextureSubRect () 為它們的幾何體且不支持 QSGTexture::Repeat 。其它值來自 CreateTextureOption 被忽略。
當 options 包含 TextureIsOpaque , the engine will create an RGB texture which returns false for QSGTexture::hasAlphaChannel (). Opaque textures will in most cases be faster to render. When this flag is not set, the texture will have an alpha channel based on the image's format.
當 options 包含 TextureHasMipmaps , the engine will create a texture which can use mipmap filtering. Mipmapped textures can not be in an atlas.
當使用 OpenGL 適配時,返迴紋理將使用
GL_TEXTURE_2D
作紋理目標和
GL_RGBA
作內部格式。重實現
QSGTexture
能創建具有不同參數的紋理。
警告: 此函數將返迴 0 若場景圖形尚未初始化。
警告: The returned texture is not memory managed by the scene graph and must be explicitly deleted by the caller on the rendering thread. This is achieved by deleting the texture from a QSGNode destructor or by using deleteLater () in the case where the texture already has affinity to the rendering thread.
可以從任何綫程中調用此函數。
另請參閱 sceneGraphInitialized () 和 QSGTexture .
這是重載函數。
創建新的 QSGTexture 對象從現有本機對象。
本機對象被包裹 (但不歸其所有) 通過結果 QSGTexture 。函數調用者負責刪除返迴的 QSGTexture ,但不會銷毀底層本機對象。
type specifies the type of the object. In practice the type is NativeObjectTexture , indicating that the native object is a texture or image of the underlying graphics API. Other types may be introduced in the future.
此函數目前僅適於 2D RGBA 紋理。
Unlike createTextureFromId(), this function supports both direct OpenGL usage and the RHI abstracted rendering path.
警告: This function will return null if the scenegraph has not yet been initialized.
使用 options to customize the texture attributes. Only the TextureHasAlphaChannel and TextureHasMipmaps are taken into account here.
警告: Unlike createTextureFromId(), this function never takes ownership of the native object, and the TextureOwnsGLTexture flag is ignored.
size 指定大小 (以像素為單位)。
nativeObjectPtr is a pointer to the native object handle. With OpenGL, the native handle is a GLuint value, so nativeObjectPtr is then a pointer to a GLuint. With Vulkan, the native handle is a VkImage, so nativeObjectPtr is a pointer to a VkImage. With Direct3D 11 and Metal nativeObjectPtr is a pointer to a ID3D11Texture2D or MTLTexture pointer.
注意: Pay attention to the fact that nativeObjectPtr is always a pointer to the native texture handle type, even if the native type itself is a pointer.
nativeLayout is only used for APIs like Vulkan. When applicable, it must specify the current image layout, such as, a VkImageLayout value.
該函數在 Qt 5.14 引入。
另請參閱 sceneGraphInitialized (), QSGTexture ,和 QSGTexture::nativeTexture ().
返迴用於此窗口的設備像素比率。
這不同於 QWindow::devicePixelRatio () in that it supports redirected rendering via QQuickRenderControl 。當使用 QQuickRenderControl , QQuickWindow is often not created, meaning it is never shown and there is no underlying native window created in the windowing system. As a result, querying properties like the device pixel ratio cannot give correct results. Use this function instead.
另請參閱 QWindow::devicePixelRatio ().
When mixing raw graphics (OpenGL, Vulkan, Metal, etc.) commands with scene graph rendering, it is necessary to call this function after recording commands to the command buffer used by the scene graph to render its main render pass. This is to avoid clobbering state.
在實踐中,此函數的調用經常是從槽連接到 beforeRenderPassRecording () 或 afterRenderPassRecording () 信號。
The function does not need to be called when recording commands to the application's own command buffer (such as, a VkCommandBuffer or MTLCommandBuffer + MTLRenderCommandEncoder created and managed by the application, not retrieved from the scene graph). With graphics APIs where no native command buffer concept is exposed (OpenGL, Direct 3D 11), beginExternalCommands () and endExternalCommands() together provide a replacement for resetOpenGLState ().
調用此函數和 beginExternalCommands () 沒有必要在 render() 實現為 QSGRenderNode 因為場景圖形會為渲染節點,隱式履行必要步驟。
注意: This function has no effect when the scene graph is using OpenGL directly and the RHI graphics abstraction layer is not in use. Refer to resetOpenGLState () in that case.
該函數在 Qt 5.14 引入。
另請參閱 beginExternalCommands ().
[override virtual protected]
bool
QQuickWindow::
event
(
QEvent
*
e
)
重實現: QWindow::event (QEvent *ev).
[override virtual protected]
void
QQuickWindow::
exposeEvent
(
QExposeEvent *
)
重實現: QWindow::exposeEvent (QExposeEvent *ev).
[override virtual protected]
void
QQuickWindow::
focusInEvent
(
QFocusEvent
*
ev
)
重實現: QWindow::focusInEvent (QFocusEvent *ev).
[override virtual protected]
void
QQuickWindow::
focusOutEvent
(
QFocusEvent
*
ev
)
重實現: QWindow::focusOutEvent (QFocusEvent *ev).
Grabs the contents of the window and returns it as an image.
It is possible to call the grabWindow() function when the window is not visible. This requires that the window is created and has a valid size and that no other QQuickWindow instances are rendering in the same process.
警告: Calling this function will cause performance problems.
警告: 隻可以從 GUI 綫程是調用此函數。
返迴引用針對 GraphicsStateInfo struct describing some of the RHI's internal state, in particular, the double or tripple buffering status of the backend (such as, the Vulkan or Metal integrations). This is relevant when the underlying graphics APIs is Vulkan or Metal, and the external rendering code wishes to perform double or tripple buffering of its own often-changing resources, such as, uniform buffers, in order to avoid stalling the pipeline.
[static]
bool
QQuickWindow::
hasDefaultAlphaBuffer
()
Returns whether to use alpha transparency on newly created windows.
該函數在 Qt 5.1 引入。
另請參閱 setDefaultAlphaBuffer ().
[override virtual protected]
void
QQuickWindow::
hideEvent
(
QHideEvent *
)
重實現: QWindow::hideEvent (QHideEvent *ev).
Returns an incubation controller that splices incubation between frames for this window. QQuickView automatically installs this controller for you, otherwise you will need to install it yourself using QQmlEngine::setIncubationController ().
The controller is owned by the window and will be destroyed when the window is deleted.
Returns whether the OpenGL context can be released during the lifetime of the QQuickWindow .
注意: This is a hint. When and how this happens is implementation specific. It also only has an effect when using the default OpenGL scene graph adaptation
Returns whether the scene graph nodes and resources can be released during the lifetime of this QQuickWindow .
注意: This is a hint. When and how this happens is implementation specific.
Returns true if the scene graph has been initialized; otherwise returns false.
[override virtual protected]
void
QQuickWindow::
keyPressEvent
(
QKeyEvent
*
e
)
重實現: QWindow::keyPressEvent (QKeyEvent *ev).
[override virtual protected]
void
QQuickWindow::
keyReleaseEvent
(
QKeyEvent
*
e
)
重實現: QWindow::keyReleaseEvent (QKeyEvent *ev).
[override virtual protected]
void
QQuickWindow::
mouseDoubleClickEvent
(
QMouseEvent
*
event
)
重實現: QWindow::mouseDoubleClickEvent (QMouseEvent *ev).
返迴目前有抓取鼠標的項。
[override virtual protected]
void
QQuickWindow::
mouseMoveEvent
(
QMouseEvent
*
event
)
重實現: QWindow::mouseMoveEvent (QMouseEvent *ev).
[override virtual protected]
void
QQuickWindow::
mousePressEvent
(
QMouseEvent
*
event
)
重實現: QWindow::mousePressEvent (QMouseEvent *ev).
[override virtual protected]
void
QQuickWindow::
mouseReleaseEvent
(
QMouseEvent
*
event
)
重實現: QWindow::mouseReleaseEvent (QMouseEvent *ev).
返迴用於渲染的 OpenGL 上下文。
注意: If the scene graph is not ready, or the scene graph is not using OpenGL (or RHI over OpenGL), this function will return null.
另請參閱 sceneGraphInitialized () 和 sceneGraphInvalidated ().
返迴用於此窗口的渲染目標。
The default is to render to the surface of the window, in which case the render target is 0.
注意: This function will return nullptr when not using the OpenGL scene graph adaptation.
注意: This function has no effect and returns nullptr when running on the RHI graphics abstraction.
另請參閱 setRenderTarget ().
返迴渲染目標的 FBO (幀緩衝對象) ID 當有設置時;否則返迴 0。
返迴目前設置的渲染目標的大小;否則返迴空大小。
返迴當前渲染器接口。值始終有效且從不為 null。
注意: 可以在任何時候調用此函數,後於構造 QQuickWindow ,即使 isSceneGraphInitialized () 仍為 false。不管怎樣,某些渲染器接口函數,尤其 QSGRendererInterface::getResource () will not be functional until the scenegraph is up and running. Backend queries, like QSGRendererInterface::graphicsApi () 或 QSGRendererInterface::shaderType (), will always be functional on the other hand.
注意: The ownership of the returned pointer stays with Qt. The returned instance may or may not be shared between different QQuickWindow instances, depending on the scenegraph backend in use. Therefore applications are expected to query the interface object for each QQuickWindow instead of reusing the already queried pointer.
該函數在 Qt 5.8 引入。
另請參閱 QSGRenderNode and QSGRendererInterface .
調用此函數以重置 OpenGL 上下文的默認狀態。
The scene graph uses the OpenGL context and will both rely on and clobber its state. When mixing raw OpenGL commands with scene graph rendering, this function provides a convenient way of resetting the OpenGL context state back to its default values.
此函數不涉及固定函數管道中的狀態。
This function does not clear the color, depth and stencil buffers. Use QQuickWindow::setClearBeforeRendering to control clearing of the color buffer. The depth and stencil buffer might be clobbered by the scene graph renderer. Clear these manually on demand.
注意: 此函數纔起作用,當使用默認 OpenGL 場景圖形適配時。
注意: This function will only reset the OpenGL context in relation to what has been changed internally as part of the OpenGL scene graph. It does not reset anything that has been changed externally such as direct OpenGL calls done inside the application code if those same calls are not used internally.
注意: This function has no effect when running on the RHI graphics abstraction and the underlying RHI backend is not OpenGL.
該函數在 Qt 5.2 引入。
另請參閱 QQuickWindow::beforeRendering (), beginExternalCommands (),和 endExternalCommands ().
[override virtual protected]
void
QQuickWindow::
resizeEvent
(
QResizeEvent
*
ev
)
重實現: QWindow::resizeEvent (QResizeEvent *ev).
[static]
QString
QQuickWindow::
sceneGraphBackend
()
返迴請求的 Qt Quick 場景圖形後端。
注意: 此函數的返迴值可能仍過時通過後續調用 setSceneGraphBackend () 直到第一 QQuickWindow 在應用程序中已構造。
該函數在 Qt 5.9 引入。
另請參閱 setSceneGraphBackend ().
調度 job to run when the rendering of this window reaches the given stage .
這很方便對於等價信號在 QQuickWindow for "one shot" tasks.
窗口擁有所有權對於 job 且會刪除它當 job 完成時。
If rendering is shut down before job has a chance to run, the job will be run and then deleted as part of the scene graph cleanup. If the window is never shown and no rendering happens before the QQuickWindow is destroyed, all pending jobs will be destroyed without their run() method being called.
若渲染發生在不同綫程,那麼 job 將發生在渲染綫程。
若 stage is NoStage , job will be run at the earliest opportunity whenever the render thread is not busy rendering a frame. If there is no OpenGL context available or the window is not exposed at the time the job is either posted or handled, it is deleted without executing the run() method. If a non-threaded renderer is in use, the run() method of the job is executed synchronously. The OpenGL context is changed to the renderer context before executing a NoStage job.
注意: This function does not trigger rendering; the jobs targeting any other stage than NoStage will be stored run until rendering is triggered elsewhere. To force the job to run earlier, call QQuickWindow::update ();
該函數在 Qt 5.4 引入。
另請參閱 beforeRendering (), afterRendering (), beforeSynchronizing (), afterSynchronizing (), frameSwapped (),和 sceneGraphInvalidated ().
設置 QML 場景圖形的渲染是否應清零顔色緩衝,先於開始渲染 enabled .
通過禁用顔色緩衝的清零,在場景圖形中渲染 OpengGL 內容是可能的。
顔色緩衝被清零,默認情況下。
警告: This flag is ignored completely when running with the RHI graphics abstraction instead of using OpenGL directly. As explicit clear commands simply do not exist in some modern APIs, the scene graph cannot offer this flexibility anymore. The images associated with a render target will always get cleared when a render pass starts. As a solution, an alternative to disabling scene graph issued clears is provided in form of the beforeRenderPassRecording () 信號。
另請參閱 clearBeforeRendering (), beforeRendering (),和 beforeRenderPassRecording ().
[static]
void
QQuickWindow::
setDefaultAlphaBuffer
(
bool
useAlpha
)
useAlpha 指定是否在新近創建的窗口中使用 Alpha 透明度。
在任何期望創建半透明窗口的應用程序中,有必要將此設為 true 先於創建第一 QQuickWindow 。默認值為 false。
該函數在 Qt 5.1 引入。
另請參閱 hasDefaultAlphaBuffer ().
Sets whether the OpenGL context should be preserved, and cannot be released until the last window is deleted, to persistent 。默認值為 true。
The OpenGL context can be released to free up graphics resources when the window is obscured, hidden or not rendering. When this happens is implementation specific.
The QOpenGLContext::aboutToBeDestroyed () signal is emitted from the QQuickWindow::openglContext () when the OpenGL context is about to be released. The QQuickWindow::sceneGraphInitialized () signal is emitted when a new OpenGL context is created for this window. Make a Qt::DirectConnection to these signals to be notified.
OpenGL 上下文仍然會被釋放,當最後一個 QQuickWindow 被刪除。
注意: This only has an effect when using the default OpenGL scene graph adaptation.
另請參閱 isPersistentOpenGLContext (), setPersistentSceneGraph (), QOpenGLContext::aboutToBeDestroyed (),和 sceneGraphInitialized ().
Sets whether the scene graph nodes and resources are
persistent
. Persistent means the nodes and resources cannot be released. The default value is
true
.
The scene graph nodes and resources can be released to free up graphics resources when the window is obscured, hidden or not rendering. When this happens is implementation specific.
The QQuickWindow::sceneGraphInvalidated () signal is emitted when cleanup occurs. The QQuickWindow::sceneGraphInitialized () signal is emitted when a new scene graph is recreated for this window. Make a Qt::DirectConnection to these signals to be notified.
The scene graph nodes and resources are still released when the last QQuickWindow 被刪除。
另請參閱 isPersistentSceneGraph (), setPersistentOpenGLContext (), sceneGraphInvalidated (),和 sceneGraphInitialized ().
將用於此窗口的渲染目標設為 fbo .
指定的 FBO (幀緩衝對象) 必須在窗口的上下文 (或與之共享的某個上下文) 中被創建。
注意: 此函數纔起作用,當使用默認 OpenGL 場景圖形適配時。
注意: 此函數不起作用,當在 RHI (渲染硬件接口) 圖形抽象上運行時。
警告: 隻可以從做渲染的綫程中調用此函數。
另請參閱 renderTarget ().
這是重載函數。
將用於此窗口的渲染目標設為 FBO (幀緩衝對象) 采用 fboId and size .
指定的 FBO (幀緩衝對象) 必須在窗口的上下文 (或與之共享的某個上下文) 中被創建。
注意: fboId can also be set to 0. In this case rendering will target the default framebuffer of whichever surface is current when the scenegraph renders. size must still be valid, specifying the dimensions of the surface.
注意: 此函數纔起作用,當使用默認 OpenGL 場景圖形適配時。
警告: 隻可以從做渲染的綫程中調用此函數。
[static]
void
QQuickWindow::
setSceneGraphBackend
(
QSGRendererInterface::GraphicsApi
api
)
請求 Qt Quick 場景圖形後端對於指定圖形 api 。後端要麼可以是內置的,要麼以動態加載插件的形式安裝。
注意: 函數調用的發生必須先於構造第一 QQuickWindow 在應用程序中。之後無法改變。
若選中後端無效 (或齣現錯誤),使用默認後端 (OpenGL 或軟件,從屬 Qt 配置)。
該函數在 Qt 5.8 引入。
另請參閱 sceneGraphBackend ().
[static]
void
QQuickWindow::
setSceneGraphBackend
(const
QString
&
backend
)
請求指定 Qt Quick 場景圖形 backend 。後端要麼可以是內置的,要麼以動態加載插件的形式安裝。
這是重載函數。
注意: 函數調用的發生必須先於構造第一 QQuickWindow 在應用程序中。之後無法改變。
若 backend 無效 (或齣現錯誤),使用默認後端 (OpenGL 或軟件,從屬 Qt 配置)。
注意:
調用此函數相當於設置
QT_QUICK_BACKEND
or
QMLSCENE_DEVICE
環境變量。不管怎樣,在卵生其它進程的應用程序中使用此 API 更安全,因為不需要擔心環境繼承。
該函數在 Qt 5.8 引入。
[static]
void
QQuickWindow::
setTextRenderType
(
QQuickWindow::TextRenderType
renderType
)
將 Qt Quick 中像文本元素的默認渲染類型設為 renderType .
注意: 設置渲染類型僅影響之後創建的元素;不會修改現有元素的渲染類型。
該函數在 Qt 5.10 引入。
另請參閱 textRenderType ().
[override virtual protected]
void
QQuickWindow::
showEvent
(
QShowEvent *
)
重實現: QWindow::showEvent (QShowEvent *ev).
[override virtual protected]
void
QQuickWindow::
tabletEvent
(
QTabletEvent
*
event
)
重實現: QWindow::tabletEvent (QTabletEvent *ev).
[static]
QQuickWindow::TextRenderType
QQuickWindow::
textRenderType
()
返迴 Qt Quick 中像文本元素的渲染類型。默認為 QQuickWindow::QtTextRendering .
該函數在 Qt 5.10 引入。
另請參閱 setTextRenderType ().
[override virtual protected]
void
QQuickWindow::
wheelEvent
(
QWheelEvent
*
event
)
重實現: QWindow::wheelEvent (QWheelEvent *ev).