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 set a "instant" value instead of a relative value of a property? Simple example...
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 776 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.
  • J Offline
    J Offline
    Jhones
    wrote on last edited by
    #1

    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
    0
    • J Offline
      J Offline
      Jhones
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved