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. How to pass variables between Rectangles?
Qt 6.11 is out! See what's new in the release blog

How to pass variables between Rectangles?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 3.3k 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.
  • F Offline
    F Offline
    franziss
    wrote on last edited by
    #1

    How do I pass a variable from rectangle bottom to rectangle left. For e.g. the code below, I like to pass the bottomMouseY variable of rectangle bottom to rectangle left

    Is it related to signals and slots? But I can't find any info about signals and slots for Qt quick

    @
    Rectangle {
    id: bottom

    MouseArea {
        id: bottomMouseAreaBorderTop
        hoverEnabled: true
        property int bottomMouseY
    
        onPressed: {
            bottomMouseY = mouseY
        }
    
        onPositionChanged: {
            // pass bottomMouseY to rectagle left
        }
    }
    

    }

    Rectangle {
    id: left

    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander
      wrote on last edited by
      #2

      Do you mean next:

      @Rectangle {
      id: left
      property alias bottomMouseY1 : bottomMouseAreaBorderTop.bottomMouseY
      }@

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3
        • Declare a property on bottom, mouseY, say
        • In the onPressed: signal handler, set the bottom.mouseY property
        • In left, declare a property, bottomMouseY, say and bind it to bottom.mouseY

        Something like this (not tested):

        @
        Rectangle {
        id: bottom
        property int mouseY: -1

        MouseArea {
            id: bottomMouseAreaBorderTop
            hoverEnabled: true
        
            onPressed: {
                bottom.mouseY = mouse.y
            }
        
            onPositionChanged: {
                bottom.mouseY = mouse.y
            }
        }
        

        }

        Rectangle {
        id: left
        bottomMouseY: bottom.mouseY
        }
        @

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • F Offline
          F Offline
          franziss
          wrote on last edited by
          #4

          Thank you Alexander and ZapB for your help, it works!

          ZapB, the second rectangle should be

          @
          Rectangle {
          id: left
          property int bottomMouseY: bottom.mouseY
          }
          @

          for it to work

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            Yeah, I did say "not tested". Thanks for pointing out my (ahem) deliberate mistake ;-)

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            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