[Interest] How to determine whether QML item is anchored?
Shawn Rutledge
Shawn.Rutledge at qt.io
Fri Apr 6 14:21:25 CEST 2018
But I wanted to query anchors at runtime once too, a few years ago; I think I’ve forgotten why.
> On 6 Apr 2018, at 13:58, Mitch Curtis <mitch.curtis at qt.io> wrote:
>
> https://bugreports.qt.io/browse/QTBUG-66264 is semi-related to this, or at least explains why we can’t really return null if they’re not set.
>
> Without having more information about your use case, it seems like quite a corner case.
>
> From: Alexander Ivash [mailto:elderorb at gmail.com]
> Sent: Friday, 6 April 2018 1:41 PM
> To: Mitch Curtis <mitch.curtis at qt.io>
> Cc: interest at qt-project.org
> Subject: Re: [Interest] How to determine whether QML item is anchored?
>
> Thanks, I'm aware of this, but this is a bit different.. Would be great to get ability to compare against something like anchors.defaultLeft or anchors.NoAnchor in future.
>
> Sent from Mailspring, the best free email app for work
> On Apr 6 2018, at 2:38 pm, Mitch Curtis <mitch.curtis at qt.io> wrote:
>
> I’m not sure if it helps in your situation, but perhaps you could take a look at AnchorChanges:
>
>
>
> http://doc.qt.io/qt-5/qml-qtquick-anchorchanges.html
>
>
>
> When the item is in an “anchored” state:
>
>
>
> states: [
>
> State {
>
> name: "anchored"
>
>
>
> AnchorChanges {
>
> target: myRect
>
> anchors.top: window.top
>
> anchors.bottom: window.bottom
>
> }
>
> PropertyChanges {
>
> target: myRect
>
> color: "green"
>
> }
>
> },
>
> State {
>
> name: "not-anchored"
>
>
>
> AnchorChanges {
>
> target: myRect
>
> anchors.top: undefined
>
> anchors.bottom: undefined
>
> }
>
>
>
> PropertyChanges {
>
> target: myRect
>
> color: "red"
>
> }
>
> }
>
> ]
>
>
>
> This assumes that you have control over the anchors, though.
>
>
>
> From: Alexander Ivash [mailto:elderorb at gmail.com]
> Sent: Friday, 6 April 2018 1:23 PM
> To: Mitch Curtis <mitch.curtis at qt.io>
> Cc: interest at qt-project.org
> Subject: Re: [Interest] How to determine whether QML item is anchored?
>
>
> Let's say I'm trying to make the logic like this: "If parent component is anchored, make a child green, otherwise make it red"
>
>
> Sent from Mailspring, the best free email app for work
> On Apr 6 2018, at 2:20 pm, Mitch Curtis <mitch.curtis at qt.io> wrote:
>
>
> What are you trying to do?
>
>
>
>
>
> From: Interest [mailto:interest-bounces+mitch.curtis=qt.io at qt-project.org] On Behalf Of Alexander Ivash
> Sent: Friday, 6 April 2018 11:40 AM
> To: interest at qt-project.org
> Subject: [Interest] How to determine whether QML item is anchored?
>
>
>
> What I'm missing? It seems like even not anchored item has anchors.right/left/top/bottom set, so it is not possible to compare with 'undefined' or something. Of course introducing change handler allows to track moment of anchoring (although still no way to track un-anchoring), but this is a bit ugly and not 'Qt-way'.
>
>
>
> Sent from Mailspring, the best free email app for work
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list