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. mapToGlobal not working when use Layout.
Qt 6.11 is out! See what's new in the release blog

mapToGlobal not working when use Layout.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 647 Views
  • 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.
  • DanimaD Offline
    DanimaD Offline
    Danima
    wrote on last edited by
    #1

    In the code below, I tried to detect the change of the x coordinate of the blue rectangle when clicking on the green rectangle. Unfortunately, onGxChanged never executes. How can I deal with this problem?

    import QtQuick 2.2
    import QtQuick.Window 2.2
    import QtQuick.Layouts 1.2
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        RowLayout
        {
            anchors.fill: parent
            Rectangle
            {
                id:rect
                color:"green"
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.preferredWidth:25
                MouseArea
                {
                    anchors.fill: parent
                    onPressed: rect.Layout.preferredWidth=50
                }
            }
            Rectangle
            {
                color:"blue"
                Layout.fillHeight: true
                Layout.fillWidth: true
                Layout.preferredWidth:25
                property int gx:parent.mapToGlobal((Qt.point(0,0))).x
                onGxChanged: console.debug("gx changed.")
    
            }
        }
    }
    
    
    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kamichanw
      wrote on last edited by
      #2

      Easy, that's because gx doesn't change at all. If you want to detect the change of gx, you can do like this

      property int gx: parent.mapToGlobal((Qt.point(x, y))).x
      
      DanimaD 2 Replies Last reply
      0
      • K Kamichanw

        Easy, that's because gx doesn't change at all. If you want to detect the change of gx, you can do like this

        property int gx: parent.mapToGlobal((Qt.point(x, y))).x
        
        DanimaD Offline
        DanimaD Offline
        Danima
        wrote on last edited by
        #3

        @Kamichanw
        ok that's working. but what about this code?

        import QtQuick 2.2
        import QtQuick.Window 2.2
        import QtQuick.Layouts 1.2
        Window {
            width: 640
            height: 480
            visible: true
            title: qsTr("Hello World")
        
            RowLayout
            {
                anchors.fill: parent
                Rectangle
                {
                    id:rect
                    color:"green"
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    Layout.preferredWidth:25
                    MouseArea
                    {
                        anchors.fill: parent
                        onPressed: rect.Layout.preferredWidth=50
                    }
                }
                Rectangle
                {
                    color:"blue"
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    Layout.preferredWidth:25
                    Rectangle
                    {
                        color:"yellow"
                        width:20
                        height: 20
                        radius: 10
                        property int gx:parent.mapToGlobal((Qt.point(x,y))).x
                        onGxChanged: console.debug("gx changed.")
        
                    }
                }
            }
        }
        
        
        DanimaD 2 Replies Last reply
        0
        • DanimaD Danima

          @Kamichanw
          ok that's working. but what about this code?

          import QtQuick 2.2
          import QtQuick.Window 2.2
          import QtQuick.Layouts 1.2
          Window {
              width: 640
              height: 480
              visible: true
              title: qsTr("Hello World")
          
              RowLayout
              {
                  anchors.fill: parent
                  Rectangle
                  {
                      id:rect
                      color:"green"
                      Layout.fillHeight: true
                      Layout.fillWidth: true
                      Layout.preferredWidth:25
                      MouseArea
                      {
                          anchors.fill: parent
                          onPressed: rect.Layout.preferredWidth=50
                      }
                  }
                  Rectangle
                  {
                      color:"blue"
                      Layout.fillHeight: true
                      Layout.fillWidth: true
                      Layout.preferredWidth:25
                      Rectangle
                      {
                          color:"yellow"
                          width:20
                          height: 20
                          radius: 10
                          property int gx:parent.mapToGlobal((Qt.point(x,y))).x
                          onGxChanged: console.debug("gx changed.")
          
                      }
                  }
              }
          }
          
          
          DanimaD Offline
          DanimaD Offline
          Danima
          wrote on last edited by
          #4

          @Danima
          some body help me.

          1 Reply Last reply
          0
          • K Kamichanw

            Easy, that's because gx doesn't change at all. If you want to detect the change of gx, you can do like this

            property int gx: parent.mapToGlobal((Qt.point(x, y))).x
            
            DanimaD Offline
            DanimaD Offline
            Danima
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • DanimaD Danima

              @Kamichanw
              ok that's working. but what about this code?

              import QtQuick 2.2
              import QtQuick.Window 2.2
              import QtQuick.Layouts 1.2
              Window {
                  width: 640
                  height: 480
                  visible: true
                  title: qsTr("Hello World")
              
                  RowLayout
                  {
                      anchors.fill: parent
                      Rectangle
                      {
                          id:rect
                          color:"green"
                          Layout.fillHeight: true
                          Layout.fillWidth: true
                          Layout.preferredWidth:25
                          MouseArea
                          {
                              anchors.fill: parent
                              onPressed: rect.Layout.preferredWidth=50
                          }
                      }
                      Rectangle
                      {
                          color:"blue"
                          Layout.fillHeight: true
                          Layout.fillWidth: true
                          Layout.preferredWidth:25
                          Rectangle
                          {
                              color:"yellow"
                              width:20
                              height: 20
                              radius: 10
                              property int gx:parent.mapToGlobal((Qt.point(x,y))).x
                              onGxChanged: console.debug("gx changed.")
              
                          }
                      }
                  }
              }
              
              
              DanimaD Offline
              DanimaD Offline
              Danima
              wrote on last edited by
              #6

              @Danima
              please somebody Help me.

              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