QQuickView 類

QQuickView 類提供用於顯示 Qt Quick 用戶界麵的窗口。 更多...

頭: #include <QQuickView>
qmake: QT += quick
Since: Qt 5.0
繼承: QQuickWindow

該類在 Qt 5.0 引入。

公共類型

enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView }
enum Status { Null, Ready, Loading, Error }

特性

公共函數

QQuickView (const QUrl & source , QWindow * parent = nullptr)
QQuickView (QQmlEngine * engine , QWindow * parent )
QQuickView (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

公共槽

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 .

成員類型文檔編製

enum QQuickView:: ResizeMode

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.

enum QQuickView:: Status

指定正加載狀態為 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 正加載網絡數據。
QQuickView::Error 3 One or more errors has occurred. Call errors () to retrieve a list of errors.

特性文檔編製

resizeMode : ResizeMode

This property holds whether the view should resize the window contents

若把此特性設為 SizeViewToRootObject (the default), the view resizes to the size of the root item in the QML.

若把此特性設為 SizeRootObjectToView , the view will automatically resize the root item to the size of the view.

訪問函數:

QQuickView::ResizeMode resizeMode () const
void setResizeMode ( QQuickView::ResizeMode )

另請參閱 initialSize ().

source : QUrl

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 )

status : const Status

組件的當前 status .

訪問函數:

QQuickView::Status status () const

通知程序信號:

void statusChanged (QQuickView::Status status )

成員函數文檔編製

QQuickView:: QQuickView (const QUrl & source , QWindow * parent = nullptr)

構造 QQuickView 采用給定 QML source and parent 。默認值對於 parent 為 0。

QQuickView:: QQuickView ( QQmlEngine * engine , QWindow * parent )

構造 QQuickView 采用給定 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 ().

QQuickView:: QQuickView ( QWindow * parent = nullptr)

構造 QQuickView 采用給定 parent 。默認值對於 parent 為 0。

[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 .

該函數在 Qt 5.14 引入。

另請參閱 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 ().

[signal] void QQuickView:: statusChanged ( QQuickView::Status status )

This signal is emitted when the component's current status 改變。

注意: 通知程序信號對於特性 status .

[override virtual] QQuickView:: ~QQuickView ()

銷毀 QQuickView .

QQmlEngine *QQuickView:: engine () const

返迴指針指嚮 QQmlEngine used for instantiating QML Components.

QList < QQmlError > QQuickView:: errors () const

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.

QSize QQuickView:: initialSize () const

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

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

QQmlContext *QQuickView:: rootContext () const

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 .

QQuickItem *QQuickView:: rootObject () const

Returns the view's root item .

QUrl QQuickView:: source () const

返迴源 URL (統一資源定位符),若有設置。

注意: getter 函數對於特性 source。

另請參閱 setSource ().