Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Global position of a QQuickItem.
Forum Updated to NodeBB v4.3 + New Features

Global position of a QQuickItem.

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 4 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Buttink
    wrote on last edited by
    #1

    So this has been asked before, but I haven't found anything to address it since QQuickItem replaced QDeclarativeItem. Here is the original question. WRONG LINK -http://qt-project.org/forums/viewthread/48092/- CORRECT LINK http://qt-project.org/forums/viewthread/10013

    The basic question is how do I know when a QQuickItem moves on the screen? How do I know if the x,y of it or any ancestor has changed? I am trying to implement a sort of tooltip that has to follow the item wherever it goes and because of transform elements (which don't edit x or y) I can't really tell where the item is on the screen and if that has changed.

    EDIT: I am dumb and copied the wrong link. I have corrected that. I will also add that I cannot find a QQuickItem::itemChange that says that the scene position changed like QGraphicsItem::itemChange did. That is why I am asking this question.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      bq. How do I know if the x,y of it or any ancestor has changed?

      Did you try onXChanged,onYChanged and onParentChanged signal handlers ?

      bq. I am trying to implement a sort of tooltip that has to follow the item wherever it goes and because of transform elements (which don’t edit x or y) I can’t really tell where the item is on the screen and if that has changed.

      Can you provide a small example for better understanding ?

      P.S: The link you posted is different I guess.

      157

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Hi buttink,

        look at "this post":http://qt-project.org/forums/viewthread/53542/ . Hope it helps somehow.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Buttink
          wrote on last edited by
          #4

          @p3c0 I'm an idiot and somehow copied the wrong link. /facepalm Let me edit my question really quick.

          @Weiland I have a solution kind of like that in QML, but you tell it what to use for the mapFromItem. The problem is that now if the item gets translated, like from a listview, the position changes but the X, Y, and Parent are all the same.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Tricky :-/

            1 Reply Last reply
            0
            • B Offline
              B Offline
              Buttink
              wrote on last edited by
              #6

              Just for reference this what I am currently using

              @Item {
              id: root
              x: d.rect.x
              y: d.rect.y
              height: d.rect.height
              width: d.rect.width

              /**
               * The target to be a ghost anchor for.
               */
              property Item target: root
              
              /*
               * TODO: Deal with the fact that floating anchor may anchored to a target that's inside a flickable (and therefore
               *       its x and y won't change when scrolling)
               *
               *       See thread: http://qt-project.org/forums/viewthread/10013
               *
               */
              
              Item {
                  id: d
              
                  property var rect: root.parent ? root.parent.mapFromItem(target.parent, target.x, target.y, target.width, target.height) : Qt.rect(0,0,0,0)
              }
              

              }@

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Buttink
                wrote on last edited by
                #7

                After doing some research, it makes sense that the scene position isn't on the QQuickItem because the scene graph should be rendering everything. The thing I'm not positive about is if QML just messes with transformers and no one is notified of updated transformers. It would make some sense considering how OpenGL works, so I'm not really sure how I am supposed to be able to pull this off.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Buttink
                  wrote on last edited by
                  #8

                  For anyone in the future, I think this could be possible by making a QSGTransform node that would move the entire subtree up making it show on the screen. I don't know how QtQuick uses the z-value though so I am looking into it.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    deleted572
                    wrote on last edited by
                    #9

                    We came to the same conclusion, i.e. you need to create some QSGNode and capture the global position with it.

                    To your Z question, what we do is to create in your main qml file an item with a very large Z value after all the others and put the item we wan't to position globally into that. That way its always on top and what remains is to set its location based on the capture from the node ( or you could try to directly access its QSGTransform node and change the X/Y of ).

                    Cheers,
                    Moeren

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved