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] Reacting on property changes
Qt 6.11 is out! See what's new in the release blog

[solved] Reacting on property changes

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

    Hi all,

    I am currently implementing a UI prototype with QML and I want to implement some kind of menu bar in pure QML/Javascript. The MenuBar component should be designed to provide an easy interface to use, so we figured out that it would be nice to implement a property that defines the orientation (top, left, right, bottom) of the menu.

    What I want to do is this: The user of the MenuBar sets a property like orientation to 'top' and the MenuBar component automatically positions it self on the top border of the parent component. I know how to do the positioning, but is there any way to react on the change of property in either pure QML or JavaScript?

    For a better understanding a short pseudo-code sample with the designated use of MenuBar:

    @
    import QtQuick 1.1
    import "BasicComponents"

    Rectangle {
    width: 800
    height: 800

    MenuBar{
        orientation: top // component will automatically align it self
        
        MenuItem{
            ...
        }
    }
    

    }
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      All properties automatically define onPropertyNameChanged slots, that can be used to react to value changes. Corresponding signal is propertyNameChanged. Of course, you have to substitute "PropertyName" with the property that you wish to handle.

      So, in your example, you can add:
      @
      import QtQuick 1.1
      import "BasicComponents"

      Rectangle {
      width: 800
      height: 800

      MenuBar{
          orientation: top // component will automatically align it self
      
          onOrientationChanged: {
                  // JS code
          }
         
          MenuItem{
              ...
          }
      }
      

      }
      @

      Is that more or less what you meant, or did I misunderstand?

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        One way would be to use conditionals in your property bindings, another would be to let the property change drive a state that you can use to modify other properties.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lycis
          wrote on last edited by
          #4

          Thanks sierdzio! Exactly what I was looking for. I never thought that the answer would be that easy :)

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            Always a pleasure. Happy coding! :D

            (Z(:^

            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