Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to set a "instant" value instead of a relative value of a property? Simple example...

    QML and Qt Quick
    1
    2
    669
    Loading More Posts
    • 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.
    • J
      Jhones last edited by

      rect2 width and height must be half of its parent width and height. But I want that just at the beginning. If the user resizes the window, I don't want the rect2 to recalculate his width and height based on its parent size. Example:

      @Rectangle {
      id: rect;
      width: 360;
      height: 360;
      color: "black";

      Rectangle {
          id: rect2;
          width: rect.width*0.5;
          height: rect.height*0.5;
          anchors.horizontalCenter: parent.horizontalCenter;
          anchors.verticalCenter: parent.verticalCenter;
          color: "white";
      }
      

      }@

      In this example, I want the rect2 to be "forever" 180 x 180.
      PS: I'm a Qt Programmer. Beginner at QtQuick.

      1 Reply Last reply Reply Quote 0
      • J
        Jhones last edited by

        I got it, guys. When we set

        @width: rect.width * 0.5;@

        is happening a binding. Not an assignment. What I should do to assign the value:
        @Component.onCompleted: {
        width = rect.width * 0.5;
        }@

        1 Reply Last reply Reply Quote 0
        • First post
          Last post