IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QQuickView Class

The QQuickView class provides a window for displaying a Qt Quick user interface.

This class was introduced in Qt 5.0.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QQuickView Class

  • Header: QQuickView

  • Since: Qt 5.0

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Quick)

    target_link_libraries(mytarget PRIVATE Qt6::Quick)

  • qmake: QT += quick

  • Inherits: QQuickWindow

  • Inherited By:

Detailed Description

This is a convenience subclass of QQuickWindow which will automatically load and display a QML scene when given the URL of the main source file. Alternatively, you can instantiate your own objects using QQmlComponent and place them in a manually setup QQuickWindow.

Typical usage:

 
Sélectionnez
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.

See Also

Member Type Documentation

 

enum QQuickView::ResizeMode

This enum specifies how to resize the view.

Constant

Value

Description

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

Specifies the loading status of the QQuickView.

Constant

Value

Description

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.

Property Documentation

 

resizeMode : ResizeMode

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.

Access functions:

  • resizeMode() const

  • void setResizeMode(QQuickView::ResizeMode)

See Also

See also 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.

Access functions:

[read-only] status : const Status

The component's current status.

Access functions:

  • status() const

Notifier signal:

Member Function Documentation

 

[explicit] QQuickView::QQuickView(QWindow *parent = nullptr)

Constructs a QQuickView with the given parent. The default value of parent is 0.

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

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() will return QQuickView::Error.

See Also

See also Status, status(), errors()

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

Constructs a QQuickView with the given QML source and parent. The default value of parent is 0.

[override virtual] QQuickView::~QQuickView()

Destroys the QQuickView.

QQmlEngine *QQuickView::engine() const

Returns a pointer to the 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.

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

[override virtual protected] void QQuickView::keyReleaseEvent(QKeyEvent *e)

[override virtual protected] void QQuickView::mouseMoveEvent(QMouseEvent *e)

[override virtual protected] void QQuickView::mousePressEvent(QMouseEvent *e)

[override virtual protected] void QQuickView::mouseReleaseEvent(QMouseEvent *e)

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.

[since 5.14] void QQuickView::setInitialProperties(const QVariantMap &initialProperties)

Sets the initial properties initialProperties with which the QML component gets initialized after calling QQuickView::setSource().

 
Sélectionnez
    QScopedPointer&lt;QQuickView&gt; view { new QQuickView };
    view-&gt;setInitialProperties({"x, 100"}, {"width", 50});
    view-&gt;setSource(QUrl::fromLocalFile("myqmlfile.qml"));
    view-&gt;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.

This function was introduced in Qt 5.14.

See Also

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 function for property source.

See Also

See also source()

QUrl QQuickView::source() const

Returns the source URL, if set.

Getter function for property source.

See Also

See also setSource()

void QQuickView::statusChanged(QQuickView::Status status)

This signal is emitted when the component's current status changes.

Notifier signal for property status.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+