The QDeclarativeView class provides a widget for displaying a Qt Declarative user interface. 更多...
| 头: | #include <QDeclarativeView> |
| Since: | Qt 4.7 |
| 继承: | QGraphicsView |
| enum | ResizeMode { SizeViewToRootObject, SizeRootObjectToView } |
| enum | Status { Null, Ready, Loading, Error } |
| QDeclarativeView (QWidget * parent = 0) | |
| QDeclarativeView (const QUrl & source , QWidget * parent = 0) | |
| virtual | ~QDeclarativeView () |
| QDeclarativeEngine * | engine () const |
| QList<QDeclarativeError> | errors () const |
| QSize | initialSize () const |
| ResizeMode | resizeMode () const |
| QDeclarativeContext * | rootContext () const |
| QGraphicsObject * | rootObject () const |
| void | setResizeMode (ResizeMode) |
| void | setSource (const QUrl & url ) |
| QUrl | source () const |
| 状态 | status () const |
| void | sceneResized (QSize size ) |
| void | statusChanged (QDeclarativeView::Status status ) |
The QDeclarativeView class provides a widget for displaying a Qt Declarative user interface.
QDeclarativeItem objects can be placed on a standard QGraphicsScene and displayed with QGraphicsView . QDeclarativeView 是 QGraphicsView subclass provided as a convenience for displaying QML files, and connecting between QML and C++ Qt objects.
QDeclarativeView provides:
典型用法:
QDeclarativeView *view = new QDeclarativeView; view->setSource(QUrl::fromLocalFile("myqmlfile.qml")); view->show();
由于 QDeclarativeView 是 QWidget -based class, it can be used to display QML interfaces within QWidget -based GUI applications that do not use the Graphics View framework.
To receive errors related to loading and executing QML with QDeclarativeView , you can connect to the statusChanged () signal and monitor for QDeclarativeView::Error . The errors are available via QDeclarativeView::errors ().
If you're using your own QGraphicsScene -based scene with QDeclarativeView , remember to enable scene's sticky focus mode and to set itemIndexMethod to QGraphicsScene::NoIndex .
另请参阅 集成 QML 代码与现有 Qt UI 代码 and 在 C++ 应用程序中使用 QML 绑定 .
This enum specifies how to resize the view.
| 常量 | 值 | 描述 |
|---|---|---|
QDeclarativeView::SizeViewToRootObject
|
0
|
The view resizes with the root item in the QML. |
QDeclarativeView::SizeRootObjectToView
|
1
|
The view will automatically resize the root item to the size of the view. |
Specifies the loading status of the QDeclarativeView .
| 常量 | 值 | 描述 |
|---|---|---|
QDeclarativeView::Null
|
0
|
This QDeclarativeView has no source set. |
QDeclarativeView::Ready
|
1
|
This QDeclarativeView has loaded and created the QML component. |
QDeclarativeView::Loading
|
2
|
This QDeclarativeView is loading network data. |
QDeclarativeView::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 canvas contents.
If this property is set to SizeViewToRootObject (the default), the view resizes with the root item in the QML.
If this property is set to SizeRootObjectToView , the view will automatically resize the root item.
Regardless of this property, the sizeHint of the view is the initial size of the root item. Note though that since QML may load dynamically, that size may change.
访问函数:
| ResizeMode | resizeMode () const |
| void | setResizeMode (ResizeMode) |
This property holds the URL of the source of the QML component.
Changing this property causes the QML component to be reloaded.
Ensure that the URL provided is full and correct, in particular, use QUrl::fromLocalFile () when loading a file from the local filesystem.
访问函数:
| QUrl | source () const |
| void | setSource (const QUrl & url ) |
另请参阅 在 QML 中加载资源 .
The component's current status .
访问函数:
| 状态 | status () const |
通知程序信号:
| void | statusChanged (QDeclarativeView::Status status ) |
构造 QDeclarativeView 采用给定 parent .
构造 QDeclarativeView with the given QML source and parent .
[虚拟]
QDeclarativeView::
~QDeclarativeView
()
销毁视图。
返回指针指向 QDeclarativeEngine 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
This function returns the root of the context hierarchy. Each QML component is instantiated in a QDeclarativeContext . QDeclarativeContext 's are essential for passing data to QML components. In QML, contexts are arranged hierarchically and this hierarchy is managed by the QDeclarativeEngine .
Returns the view's root item .
[signal]
void
QDeclarativeView::
sceneResized
(
QSize
size
)
This signal is emitted when the view is resized to size .