Notices


Reply
Thread Tools
pichlo's Avatar
Posts: 5,560 | Thanked: 17,338 times | Joined on Sep 2012 @ UK
#1
A QML newbie here. The title is deliberately vague to allow continuing in the future with different QML related questions in the same thread.

To start it off...

I have a layout that changes depending on some external parameter, for example a screen orientation.
For example:
Code:
Grid {
  id: myGrid
  ...

  Rectangle {
    id: myRectangle1
    ...
  }

  Rectangle {
    id: myRectangle2
    ...
  }

  Rectangle {
    id: myRectangle3
    ...
  }
}
I also have another element in a completely different module that I want to anchor to one of the elements in my layout, e.g. myRectangle3 in the above example. Remember it can move around.
How do I do it?

A simple and naive solution below does not work:
Code:
Rectangle {
  id: myOtherRectangle
  anchorItem: myGrid.myRectangle3
  ...
}
I can anchor to myGrid but not to myGrid.myRectangle3. I am sure there is a simple solution that I am missing. I tried RTFM but if anything, it did my head in even more.
__________________
In particle accelerators atoms are indeed not only touching each others. But banging together in a massive explosive orgasm.
-- nieldk in a TMO post
 

The Following 2 Users Say Thank You to pichlo For This Useful Post:
Posts: 303 | Thanked: 1,400 times | Joined on Oct 2013 @ France
#2
I may be able to help, but need some more details.
you say that those two parts being in two "completely differents" modules. what kind of separation is there between them (parents, childrens, separate files....)

I am not sure where you found this anchoritem properties (no computer at hand...).
I usually use the bunch of anchors.* properties you can find in this doc : http://doc.qt.io/qt-5/qml-qtquick-item.html

there are several kind of anchors and dedicated properties for each. anchors.fill for exemple sets all sides to match another item, but you can also align only some sides or the vertical and horizontal center as you wish.
maybe explain what you need the anchored item do relative to the target (fill it, center in it, right align...).
 

The Following 2 Users Say Thank You to Zeta For This Useful Post:
coderus's Avatar
Posts: 6,158 | Thanked: 11,660 times | Joined on Nov 2011 @ Open Mobile Platform, Innopolis, Russia
#3
in grid:
Code:
property alias rect1: myRectangle1
in external rectangle:
Code:
anchor.left: grid.rect1.left
__________________
Twitter | Openrepos | GitHub | PayPal.Me
 

The Following 2 Users Say Thank You to coderus For This Useful Post:
pichlo's Avatar
Posts: 5,560 | Thanked: 17,338 times | Joined on Sep 2012 @ UK
#4
@Zeta,
myGrid and myOtherRectangle are siblings.
I found anchorItem in some other source where I took the inspiration from. I did not find it myself.

@coderus,
Thanks. I had tried something similar but that did not work either. Apparently you can only anchor to a parent or a sibling. myGrid is a siblibg, myGrid.rect1 is not.

Never mind, I think I figured it out. I need to refactor the code at a higher level. I could write more details when I get back to a PC.
__________________
In particle accelerators atoms are indeed not only touching each others. But banging together in a massive explosive orgasm.
-- nieldk in a TMO post

Last edited by pichlo; 2018-09-28 at 18:41.
 

The Following 2 Users Say Thank You to pichlo For This Useful Post:
pichlo's Avatar
Posts: 5,560 | Thanked: 17,338 times | Joined on Sep 2012 @ UK
#5
Originally Posted by pichlo View Post
@coderus,
Thanks. I had tried something similar but that did not work either. Apparently you can only anchor to a parent or a sibling. myGrid is a siblibg, myGrid.rect1 is not.
For the peace of mind, I tried it exactly as suggested (my previous solution did not use 'property alias', it used 'property Rectangle'). But, sadly,
Code:
QML Notification: Cannot anchor to an item that isn't a parent or sibling.
Refactoring it is
__________________
In particle accelerators atoms are indeed not only touching each others. But banging together in a massive explosive orgasm.
-- nieldk in a TMO post
 

The Following 2 Users Say Thank You to pichlo For This Useful Post:
Markkyboy's Avatar
Posts: 318 | Thanked: 439 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#6
Originally Posted by pichlo View Post
.... I am sure there is a simple solution that I am missing. I tried RTFM but if anything, it did my head in even more.....
I hear that one, the examples set on many Qt/Qml pages are brief to say the least, or they plunge into great deal, causing those headaches and leaving me none the wiser. It strikes me that the authors of these pages assume you already have an understanding of how this stuff works, either way it's all mostly rather vague and what may work in Qt Creator is not always applicable to SFOS because of proprietary modules.
__________________
| Openrepos | T.J.C. |

Don't just sit there standing around, pick up a shovel and sweep up!
 

The Following 4 Users Say Thank You to Markkyboy For This Useful Post:
Reply

Tags
programming, qml components

Thread Tools

 
Forum Jump


All times are GMT. The time now is 16:19.