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. Changing QML property from C++ : how to change width of QML property?
Forum Updated to NodeBB v4.3 + New Features

Changing QML property from C++ : how to change width of QML property?

Scheduled Pinned Locked Moved QML and Qt Quick
3 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.
  • B Offline
    B Offline
    bkamps
    wrote on last edited by
    #1

    I have a QML element connected to a C++ object with just one property: counter.

    When I update the counter property from C++ I want to update the width of my QML element (it's a Rectangle).

    I have tried:

    @
    Rectangle {
    property int counter = model.counter
    width: counter * 10
    }
    @

    The width does not change when I change the counter property... How come?

    [edit: Highlight added / Denis Kormalev]

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

      Try this:

      @
      Rectangle {
      width: 10 * model.counter
      }
      @

      Are you sure that you are correctly exposing your c++ object to QML? I assumed in the above that your object is correctly exposed as model and that the property is called counter.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

        I think you've meant
        @
        Rectangle {
        property int counter: model.counter
        width: counter * 10
        }
        @
        Do you change qml property or property of model from c++? If second, then you should use alias instead of full qml property. And don't forget about emitting signal on property change (one mentioned in NOTIFY).

        P.S. And please, don't forget to highlight your code

        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