[Development] Window{} API for QML

Adriano Rezende adriano.rezende at openbossa.org
Thu Nov 10 19:01:32 CET 2011


On Mon, Nov 7, 2011 at 5:32 AM, Alan Alpert <alan.alpert at nokia.com> wrote:
> Given that there can be Desktop Components providing the full API for desktop
> windows (and this is being discussed on the qt-components ML already), I
> propose the following minimal Window{} API for QML core (i.e. inside the
> QtDeclarative library)
>
> Window {//Inherits QQuickItem
>    property string title: "untitled"
>    property bool fullscreen: true
>
>    property int x
>    property int y
>    property int width
>    property int height
>    property bool visible
> }
>
> Now this item would end up being reparented into another QQuickCanvas on
> another window after being created in the same engine as the main file. This
> allows bindings to work between windows just fine. Because of the reparenting
> though there are a few changes from QQuickItem which is why I've duplicated
> x/y/width/height/visible. Arguably it shouldn't be a QQuickItem because of
> this, but I think the easy access to anchors is worth it.

I think the Window element should not inherit from QQuickItem, since
it's not an element in the render tree; it's basically a window
representation that is not affected by parent transformations or
effective opacity. The anchors feature is not a big advantage if it
brings to an API bloat; one could also achieve the same results
creating a wrapper like the following:

Item {
    anchors.fill: parent

    Window {
        x: // map to global
        y: // map to global
        width: parent.width
        height: parent.height
    }
}

Internally the Window element could create a (or maybe inherit from)
QQuickCanvas or QQuickView and move its children to a root contentItem
like the Flickable API.

This would provide a more symmetric (and QML oriented) API, since we
could do something like:

// main.qml
Window { // top level window
     Item {
         Window { // sub window

         }
    }
}

The view could also be retrieved from the C++ side like the following:

QQuickView *view = QQuickView::loadFromFile("main.qml");


Br,
Adriano



More information about the Development mailing list