Active Topics

 


Reply
Thread Tools
pichlo's Avatar
Posts: 6,447 | Thanked: 20,981 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.
__________________
Русский военный корабль, иди нахуй!
 

The Following 2 Users Say Thank You to pichlo For This Useful Post:
Posts: 339 | Thanked: 1,623 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,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#3
in grid:
Code:
property alias rect1: myRectangle1
in external rectangle:
Code:
anchor.left: grid.rect1.left
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following 2 Users Say Thank You to coderus For This Useful Post:
pichlo's Avatar
Posts: 6,447 | Thanked: 20,981 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.
__________________
Русский военный корабль, иди нахуй!

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: 6,447 | Thanked: 20,981 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
__________________
Русский военный корабль, иди нахуй!
 

The Following 2 Users Say Thank You to pichlo For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 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.
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

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

Tags
programming, qml components


 
Forum Jump


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