Quantcast
Channel: Installation and Deployment
Viewing all articles
Browse latest Browse all 22112

QML Draw order

$
0
0
How does QML draw order work, especially given that QML is declarative rather than imperative? If I have this code: import QtQuick 1.1   Rectangle {     id: outerRect     color: "red"     Text {         anchors.centerIn: parent         text: "outerRect"     }     x: 0; y: 0; width: 250; height: 150       Rectangle {         id: midLevelRect1         color: "blue"         Text {             anchors.centerIn: parent             text: "midLevelRect1"         }         x: 10; y: 10; width: 75; height: 75           Rectangle {             id: innerRect             color: "green"             Text {                 anchors.centerIn: parent                 text: "innerRect"             }             x: 50; y: 50; width: 75; height: 75         }     }       Rectangle {         id: midLevelRect2         color: "yellow"         Text {             anchors.centerIn: parent             text: "midLevelRect2"         }           x: 100; y: 10; width: 75; height: 75     }   } I kind of expected (or hoped) to see this: But what I actually see is this: Its occurred to me that in a way, declarative syntax doesn’t provide a really great way to structure draw order. Most functional languages don’t necessarily require a particular applicative order and draw order here is almost sort of a side-effect of the applicative ordering that the QML runtime has been designed around. How does QML do this? It’s pretty clear that behind the scenes the qml runtime is evaluating the object tree in a simple and strict dfs order – is this necessarily true all the time? More to the point, I’m trying to implement something like tooltips. With those screen shots you can imagine the green rectangle being a tooltip and the blue and yellow rectangles are widgets/QWidgets/QML Items. To get the tooltip to display on top of everything, including adjacent widgets, I ended up having to declare it under the common root – in this case I had to declare innerRect underneath outerRect rather than midLevelRect1, even though the tool tip really sort of belongs to midLevelRect1. Where this really causes problems is with view delegates in the qml data model – like having a tooltip for an item in a ListView. I would have thought that setting innerRect’s z property to some large number would draw it over midLevelRect2, but it doesn’t. If this isn’t what z is for, why do we even have it in Item? I’m using QtQuick 1.0 in Qt 4.8.4 on Windows, but 4.8.4 on OSX behaves identically. Can anyone fill me in?

Viewing all articles
Browse latest Browse all 22112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>