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. [solved]How do I detect if a rect's members are changed?
Forum Updated to NodeBB v4.3 + New Features

[solved]How do I detect if a rect's members are changed?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 1.4k 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
    bobbaluba
    wrote on last edited by
    #1

    When I have a rect property, is there an event that is fired the members of the rect are changed? I tried using onMyRectChanged, but that seems to only fire when I assign a different rect to the not when I change the members of the rect.

    @Item {
    property rect myRect: "0,0,1x1"
    onMyRectChanged: {
    //this only happens when myRect is reassigned
    //not if I do myRect.x = 10
    console.log("rect reassigned");
    }
    }@

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      No there is no catch-all signal for any property. You get notifications for individual properties, so you will have to add print statements to "onXChanged", "onWidthChanged" etc individually by using for instance a Connections element:

      @
      Connections {
      target: myRect
      onWidthChanged: print("foo)"
      }
      @

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bobbaluba
        wrote on last edited by
        #3

        Have you confirmed that this actually works?

        I get this error:
        @Unable to assign QRectF to QObject*@

        EDIT:
        This is kind of embarrassing... So it seems I simplified my code too much before asking the question. I am exposing a C++ class to QML and I forgot to emit the NOTIFY signal :P. Anyway, now the handler is called whenever I change the attributes of the QRectF. Probably since setMyRect is the only mutating function on my c++ class?

        Thanks, anyway, it was useful to learn about the connections component.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          onek24
          wrote on last edited by
          #4

          [quote author="bobbaluba" date="1394098502"]Have you confirmed that this actually works?

          I get this error:
          @Unable to assign QRectF to QObject*@
          [/quote]
          see

          bq. individually by using for instance a Connections element

          I might be wrong but you should be able to access the notifications directly by:
          @Item {
          property rect myRect: "0,0,1x1"
          onWidthChanged: print("foo")
          onXChanged: print("bar")
          }@

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bobbaluba
            wrote on last edited by
            #5

            onek24 that will just give you notifications when the dimensions of the Item itself changes. Item has properties called width, height, x, y.

            1 Reply Last reply
            0
            • O Offline
              O Offline
              onek24
              wrote on last edited by
              #6

              [quote author="bobbaluba" date="1394100498"]onek24 that will just give you notifications when the dimensions of the Item itself changes. Item has properties called width, height, x, y.[/quote]

              Yes that is right, my answer was based on the answer of Jens who also used the notification onWidthChanged. I just wanted to provide you a way without the Connector.

              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