[Development] AplicationWindow, QQuickWindow, contentRotation and setting width and height of contentItem

Alan Alpert 416365416c at gmail.com
Fri Aug 2 19:58:19 CEST 2013


On Thu, Aug 1, 2013 at 11:22 PM, Tomasz Olszak <olszak.tomasz at gmail.com> wrote:
>> Like Flickable, you aren't supposed to control the contentItem of
>> Window. It's only exposed because it unfortunately cannot be fully
>> hidden as an implementation detail (at least not without breaking
>> certain edge cases). So it's deliberate that you aren't able to
>> override this like a binding.
>>
> I understand Flickable case but could you please point out Window edge
> cases?

Primarily they come because Window is not an item. Example, if you
want to add an item dynamically to Window you can't do "item.parent =
window //fails" - not an item. You need to do "item.parent =
window.contentItem".

>> What's the problem with creating your own item instead of trying to
>> reuse the contentItem? Something like:
>> /* ApplicationWindow.qml */
>> Window {
>>     default property alias myData: myContentItem.data
>>     Item {
>>         id: myContentItem
>>         //All rotation logic goes here
>>     }
>> }
>
>
> Problem is with Items like ModalPopupBehavior from QtQuick.Controls:
>
> Item {
>     ...
>     property Item root: findRoot()
>     function findRoot() {
>         var p = parent;
>         while(p.parent != undefined)
>             p = p.parent;
>
>         return p;
>     }
>
>    ...
>     anchors.fill: parent
>
>     states: State {
>         name: "active"
>         when: Qt.isQtObject(popupLoader.item) && popupLoader.item.opacity >
> 0
>         ParentChange { target: popupBehavior; parent: root }
>     }
> }
>
> If I add my own Item then ModalPopupBehavior will not be rotated because its
> parent will be contentItem. Of course I can change condition in findRoot
> function to:
>         while(p.parent.parent != undefined)
> but I think that most app developers won't do this in their own modals.

You should also be able to work around it inside your
ApplicationWindow by hiding the parent property on your content item.
Something like "property Item parent: null" should make it look like
the root of the tree. It's not great, but you actually want to pretend
to be the root of the tree (it's not just a ModalPopupBehavior hack).

The other workaround that comes to mind is to define your
ApplicationWindow in C++ by subclassing QQuickWindow.h and
implementing your own contentItem which does include the rotation
behavior.

Would either approach be sufficient for your needs?

--
Alan Alpert



More information about the Development mailing list