QQuickView 类提供用于显示 Qt Quick 用户界面的窗口。 更多...
头: | #include <QQuickView> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Quick)
target_link_libraries(mytarget PRIVATE Qt6::Quick) |
qmake: | QT += quick |
继承: | QQuickWindow |
enum | ResizeMode { SizeViewToRootObject, SizeRootObjectToView } |
enum | Status { Null, Ready, Loading, Error } |
QQuickView (QWindow * parent = nullptr) | |
QQuickView (QQmlEngine * engine , QWindow * parent ) | |
QQuickView (const QUrl & source , QWindow * parent = nullptr) | |
(从 6.7 起)
|
QQuickView (QAnyStringView uri , QAnyStringView typeName , QWindow * parent = nullptr) |
virtual | ~QQuickView () override |
QQmlEngine * | engine () const |
QList<QQmlError> | errors () const |
QSize | initialSize () const |
QQuickView::ResizeMode | resizeMode () const |
QQmlContext * | rootContext () const |
QQuickItem * | rootObject () const |
void | setResizeMode (QQuickView::ResizeMode) |
QUrl | source () const |
QQuickView::Status | status () const |
(从 6.7 起)
void
|
loadFromModule (QAnyStringView uri , QAnyStringView typeName ) |
void | setInitialProperties (const QVariantMap & initialProperties ) |
void | setSource (const QUrl & url ) |
void | statusChanged (QQuickView::Status status ) |
virtual void | keyPressEvent (QKeyEvent * e ) override |
virtual void | keyReleaseEvent (QKeyEvent * e ) override |
virtual void | mouseMoveEvent (QMouseEvent * e ) override |
virtual void | mousePressEvent (QMouseEvent * e ) override |
virtual void | mouseReleaseEvent (QMouseEvent * e ) override |
这是方便子类化的 QQuickWindow 将自动加载并显示 QML 场景当有给出主源文件的 URL 时。另外,可以实例化自己的对象使用 QQmlComponent 并放置它们以手动设置 QQuickWindow .
典型用法:
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQuickView *view = new QQuickView; view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); view->show(); return app.exec(); }
To receive errors related to loading and executing QML with QQuickView, you can connect to the statusChanged () signal and monitor for QQuickView::Error . The errors are available via QQuickView::errors ().
QQuickView also manages sizing of the view and root object. By default, the resizeMode is SizeViewToRootObject , which will load the component and resize it to the size of the view. Alternatively the resizeMode may be set to SizeRootObjectToView which will resize the view to the size of the root object.
另请参阅 将 C++ 类型属性暴露给 QML and QQuickWidget .
This enum specifies how to resize the view.
常量 | 值 | 描述 |
---|---|---|
QQuickView::SizeViewToRootObject
|
0
|
The view resizes with the root item in the QML. |
QQuickView::SizeRootObjectToView
|
1
|
The view will automatically resize the root item to the size of the view. |
Specifies the loading status of the QQuickView .
常量 | 值 | 描述 |
---|---|---|
QQuickView::Null
|
0
|
This QQuickView has no source set. |
QQuickView::Ready
|
1
|
This QQuickView has loaded and created the QML component. |
QQuickView::Loading
|
2
|
This QQuickView is loading network data. |
QQuickView::Error
|
3
|
One or more errors has occurred. Call errors () to retrieve a list of errors. |
This property holds whether the view should resize the window contents
If this property is set to SizeViewToRootObject (the default), the view resizes to the size of the root item in the QML.
If this property is set to SizeRootObjectToView , the view will automatically resize the root item to the size of the view.
访问函数:
QQuickView::ResizeMode | resizeMode () const |
void | setResizeMode (QQuickView::ResizeMode) |
另请参阅 initialSize ().
This property holds the URL of the source of the QML component.
Ensure that the URL provided is full and correct, in particular, use QUrl::fromLocalFile () when loading a file from the local filesystem.
Note that setting a source URL will result in the QML component being instantiated, even if the URL is unchanged from the current value.
访问函数:
QUrl | source () const |
void | setSource (const QUrl & url ) |
[read-only]
status
: const
Status
The component's current status .
访问函数:
QQuickView::Status | status () const |
通知程序信号:
void | statusChanged (QQuickView::Status status ) |
[explicit]
QQuickView::
QQuickView
(
QWindow
*
parent
= nullptr)
Constructs a QQuickView with the given parent 。默认值对于 parent 为 0。
Constructs a QQuickView with the given QML engine and parent .
Note: In this case, the QQuickView 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 () 会返回 QQuickView::Error .
另请参阅 Status , status (),和 errors ().
[explicit]
QQuickView::
QQuickView
(const
QUrl
&
source
,
QWindow
*
parent
= nullptr)
Constructs a QQuickView with the given QML
source
and
parent
。默认值对于
parent
is
nullptr
.
[explicit, since 6.7]
QQuickView::
QQuickView
(
QAnyStringView
uri
,
QAnyStringView
typeName
,
QWindow
*
parent
= nullptr)
Constructs a QQuickView with the element specified by
uri
and
typeName
和父级
parent
。默认值对于
parent
is
nullptr
.
该函数在 Qt 6.7 引入。
另请参阅 loadFromModule .
[override virtual noexcept]
QQuickView::
~QQuickView
()
销毁 QQuickView .
返回指针指向 QQmlEngine used for instantiating QML Components.
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.
Returns the initial size of the root object.
若 resizeMode is QQuickItem::SizeRootObjectToView the root object will be resized to the size of the view. initialSize contains the size of the root object before it was resized.
[override virtual protected]
void
QQuickView::
keyPressEvent
(
QKeyEvent
*
e
)
重实现: QQuickWindow::keyPressEvent (QKeyEvent *e).
[override virtual protected]
void
QQuickView::
keyReleaseEvent
(
QKeyEvent
*
e
)
重实现: QQuickWindow::keyReleaseEvent (QKeyEvent *e).
[slot, since 6.7]
void
QQuickView::
loadFromModule
(
QAnyStringView
uri
,
QAnyStringView
typeName
)
Loads the QML component identified by
uri
and
typeName
. If the component is backed by a QML file,
source
will be set accordingly. For types defined in
C++
,
source
will be empty.
If any source was set before this method was called, it will be cleared.
Calling this method multiple times with the same uri and typeName will result in the QML component being reinstantiated.
该函数在 Qt 6.7 引入。
另请参阅 setSource , QQmlComponent::loadFromModule ,和 QQmlApplicationEngine::loadFromModule .
[override virtual protected]
void
QQuickView::
mouseMoveEvent
(
QMouseEvent
*
e
)
重实现: QQuickWindow::mouseMoveEvent (QMouseEvent *event).
[override virtual protected]
void
QQuickView::
mousePressEvent
(
QMouseEvent
*
e
)
重实现: QQuickWindow::mousePressEvent (QMouseEvent *event).
[override virtual protected]
void
QQuickView::
mouseReleaseEvent
(
QMouseEvent
*
e
)
重实现: QQuickWindow::mouseReleaseEvent (QMouseEvent *event).
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 .
Returns the view's root item .
[slot]
void
QQuickView::
setInitialProperties
(const
QVariantMap
&
initialProperties
)
Sets the initial properties initialProperties with which the QML component gets initialized after calling QQuickView::setSource ().
QScopedPointer<QQuickView> view { new QQuickView }; view->setInitialProperties({"x, 100"}, {"width", 50}); view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); view->show();
注意: You can only use this function to initialize top-level properties.
注意:
This function should always be called before
setSource
, as it has no effect once the component has become
Ready
.
另请参阅 QQmlComponent::createWithInitialProperties ().
[slot]
void
QQuickView::
setSource
(const
QUrl
&
url
)
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 QUrl::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.
注意: setter 函数对于特性 source .
另请参阅 source ().
Returns the source URL, if set.
注意: getter 函数对于特性 source。
另请参阅 setSource ().
[signal]
void
QQuickView::
statusChanged
(
QQuickView::Status
status
)
This signal is emitted when the component's current status 改变。
注意: 通知程序信号对于特性 status .