QQuickWidgetclass provides a widget for displaying a Qt Quick user interface. 更多 …
def
engine
()
def
errors
()
def
format
()
def
grabFramebuffer
()
def
initialSize
()
def
quickWindow
()
def
resizeMode
()
def
rootContext
()
def
rootObject
()
def
setClearColor
(color)
def
setFormat
(format)
def
setResizeMode
(arg__1)
def
source
()
def
status
()
def
setContent
(url, component, item)
def
setSource
(arg__1)
def
sceneGraphError
(error, message)
def
statusChanged
(arg__1)
This is a convenience wrapper for
QQuickWindow将自动加载并显示 QML 场景当有给出主源文件的 URL 时。另外,可以实例化自己的对象使用QQmlComponentand place them in a manually set upQQuickWidget.典型用法:
QQuickWidget *view = new QQuickWidget; view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); view->show();To receive errors related to loading and executing QML with
QQuickWidget, you can connect to thestatusChanged()signal and monitor forError. The errors are available viaerrors().
QQuickWidgetalso manages sizing of the view and root object. By default, theresizeModeisSizeViewToRootObject, which will load the component and resize it to the size of the view. Alternatively theresizeModemay be set toSizeRootObjectToViewwhich will resize the view to the size of the root object.注意
QQuickWidgetis an alternative to usingQQuickViewandcreateWindowContainer(). The restrictions on stacking order do not apply, makingQQuickWidgetthe more flexible alternative, behaving more like an ordinary widget. This comes at the expense of performance. UnlikeQQuickWindowandQQuickView,QQuickWidgetinvolves rendering into OpenGL framebuffer objects. This will naturally carry a minor performance hit.注意
使用
QQuickWidgetdisables the threaded render loop on all platforms. This means that some of the benefits of threaded rendering, for example Animator classes and vsync driven animations, will not be available.注意
Avoid calling
winId()在QQuickWidget. This function triggers the creation of a native window, resulting in reduced performance and possibly rendering glitches. The entire purpose ofQQuickWidgetis to render Quick scenes without a separate native window, hence making it a native widget should always be avoided.
QQuickWidgethonorsisPersistentSceneGraph(), meaning that applications can decide - by callingsetPersistentSceneGraph()on the window returned from thequickWindow()function - to let scenegraph nodes and other Qt Quick scene related resources be released whenever the widget becomes hidden. By default persistency is enabled, just like withQQuickWindow.When running with the OpenGL backend of the scene graph,
QQuickWindowoffers the possibility to disable persistent OpenGL contexts as well. This setting is currently ignored byQQuickWidgetand the context is always persistent. The OpenGL context is thus not destroyed when hiding the widget. The context is destroyed only when the widget is destroyed or when the widget gets reparented into another top-level widget’s child hierarchy. However, some applications, in particular those that have their own graphics resources due to performing custom OpenGL rendering in the Qt Quick scene, may wish to disable the latter since they may not be prepared to handle the loss of the context when moving aQQuickWidgetinto another window. Such applications can set the QCoreApplication::AA_ShareOpenGLContexts attribute. For a discussion on the details of resource initialization and cleanup, refer to theQOpenGLWidget文档编制。注意
QQuickWidgetoffers less fine-grained control over its internal OpenGL context thanQOpenGLWidget, and there are subtle differences, most notably that disabling the persistent scene graph will lead to destroying the context on a window change regardless of the presence of QCoreApplication::AA_ShareOpenGLContexts.
Putting other widgets underneath and making the
QQuickWidgettransparent will not lead to the expected results: the widgets underneath will not be visible. This is because in practice theQQuickWidgetis drawn before all other regular, non-OpenGL widgets, and so see-through types of solutions are not feasible. Other type of layouts, like having widgets on top of theQQuickWidget, will function as expected.When absolutely necessary, this limitation can be overcome by setting the
WA_AlwaysStackOnTopattribute on theQQuickWidget. Be aware, however that this breaks stacking order. For example it will not be possible to have other widgets on top of theQQuickWidget, so it should only be used in situations where a semi-transparentQQuickWidgetwith other widgets visible underneath is required.This limitation only applies when there are other widgets underneath the
QQuickWidgetinside the same window. Making the window semi-transparent, with other applications and the desktop visible in the background, is done in the traditional way: SetWA_TranslucentBackgroundon the top-level window, request an alpha channel, and change the Qt Quick Scenegraph’s clear color totransparent凭借setClearColor().
In addition to OpenGL, the
softwarebackend of Qt Quick also supportsQQuickWidget. Other backends, for example the Direct 3D 12 one, are not compatible however and attempting to construct aQQuickWidgetwill lead to problems.
On press of the
[TAB]key, the item inside theQQuickWidgetgets focus. If this item can handle[TAB]key press, focus will change accordingly within the item, otherwise the next widget in the focus chain gets focus.另请参阅
将 C++ 类型属性暴露给 QML Qt Quick Widgets 范例
QQuickView
QQuickWidget
(
engine
,
parent
)
¶
QQuickWidget([parent=None])
QQuickWidget(source[, parent=None])
- param parent
QWidget- param source
QUrl- param engine
QQmlEngine
构造
QQuickWidget
with the given QML
engine
and
parent
.
Note: In this case, the
QQuickWidget
does not own the given
engine
object; it is the caller’s responsibility to destroy the engine. If the
engine
is deleted before the view,
status()
will return
Error
.
构造
QQuickWidget
采用给定
parent
. The default value of
parent
为 0。
PySide2.QtQuickWidgets.QQuickWidget.
ResizeMode
¶
This enum specifies how to resize the view.
|
常量 |
描述 |
|---|---|
|
QQuickWidget.SizeViewToRootObject |
The view resizes with the root item in the QML. |
|
QQuickWidget.SizeRootObjectToView |
The view will automatically resize the root item to the size of the view. |
PySide2.QtQuickWidgets.QQuickWidget.
Status
¶
Specifies the loading status of the
QQuickWidget
.
|
常量 |
描述 |
|---|---|
|
QQuickWidget.Null |
This
|
|
QQuickWidget.Ready |
This
|
|
QQuickWidget.Loading |
This
|
|
QQuickWidget.Error |
One or more errors occurred. Call
|
PySide2.QtQuickWidgets.QQuickWidget.
engine
(
)
¶
QQmlEngine
返回指针指向
QQmlEngine
used for instantiating QML Components.
PySide2.QtQuickWidgets.QQuickWidget.
errors
(
)
¶
Return the list of errors that occurred during the last compile or create operation. When the status is not
Error
, an empty list is returned.
另请参阅
PySide2.QtQuickWidgets.QQuickWidget.
format
(
)
¶
QSurfaceFormat
Returns the actual surface format.
If the widget has not yet been shown, the requested format is returned.
另请参阅
PySide2.QtQuickWidgets.QQuickWidget.
grabFramebuffer
(
)
¶
QImage
Renders a frame and reads it back into an image.
注意
This is a potentially expensive operation.
PySide2.QtQuickWidgets.QQuickWidget.
initialSize
(
)
¶
QSize
Returns the initial size of the root object.
若
resizeMode
is
SizeRootObjectToView
, the root object will be resized to the size of the view. This function returns the size of the root object before it was resized.
PySide2.QtQuickWidgets.QQuickWidget.
quickWindow
(
)
¶
QQuickWindow
Returns the offscreen
QQuickWindow
which is used by this widget to drive the Qt Quick rendering. This is useful if you want to use
QQuickWindow
APIs that are not currently exposed by
QQuickWidget
, for instance connecting to the
beforeRendering()
signal in order to draw native OpenGL content below Qt Quick’s own rendering.
警告
Use the return value of this function with caution. In particular, do not ever attempt to show the
QQuickWindow
, and be very careful when using other
QWindow
-only APIs.
PySide2.QtQuickWidgets.QQuickWidget.
resizeMode
(
)
¶
另请参阅
PySide2.QtQuickWidgets.QQuickWidget.
rootContext
(
)
¶
QQmlContext
This function returns the root of the context hierarchy. Each QML component is instantiated in a
QQmlContext
.
QQmlContext
‘s are essential for passing data to QML components. In QML, contexts are arranged hierarchically and this hierarchy is managed by the
QQmlEngine
.
PySide2.QtQuickWidgets.QQuickWidget.
rootObject
(
)
¶
QQuickItem
Returns the view’s root
item
. Can be null when
setSource()
has not been called, if it was called with broken
QtQuick
code or while the
QtQuick
contents are being created.
PySide2.QtQuickWidgets.QQuickWidget.
sceneGraphError
(
error
,
message
)
¶
error
–
SceneGraphError
message – unicode
PySide2.QtQuickWidgets.QQuickWidget.
setClearColor
(
color
)
¶
color
–
QColor
Sets the clear
color
. By default this is an opaque color.
To get a semi-transparent
QQuickWidget
, call this function with
color
设为
transparent
, set the
WA_TranslucentBackground
widget attribute on the top-level window, and request an alpha channel via
setFormat()
.
另请参阅
setColor()
PySide2.QtQuickWidgets.QQuickWidget.
setContent
(
url
,
component
,
item
)
¶
url
–
QUrl
component
–
QQmlComponent
item
–
QObject
Sets the source
url
,
component
and content
item
(root of the QML object hierarchy) directly.
PySide2.QtQuickWidgets.QQuickWidget.
setFormat
(
format
)
¶
format
–
QSurfaceFormat
Sets the surface
format
for the context and offscreen surface used by this widget.
Call this function when there is a need to request a context for a given OpenGL version or profile. The sizes for depth, stencil and alpha buffers are taken care of automatically and there is no need to request those explicitly.
另请参阅
setFormat()
format()
format()
PySide2.QtQuickWidgets.QQuickWidget.
setResizeMode
(
arg__1
)
¶
arg__1
–
ResizeMode
另请参阅
PySide2.QtQuickWidgets.QQuickWidget.
setSource
(
arg__1
)
¶
arg__1
–
QUrl
Sets the source to the
url
, loads the QML component and instantiates it.
Ensure that the URL provided is full and correct, in particular, use
fromLocalFile()
when loading a file from the local filesystem.
Calling this method multiple times with the same URL will result in the QML component being reinstantiated.
另请参阅
PySide2.QtQuickWidgets.QQuickWidget.
source
(
)
¶
QUrl
Returns the source URL, if set.
另请参阅