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. Change QML item property in c++ code
Forum Updated to NodeBB v4.3 + New Features

Change QML item property in c++ code

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 1.4k Views 2 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.
  • M Offline
    M Offline
    msauer75
    wrote on last edited by
    #1

    Hi,
    at the moment I am working on my first QML/QtQuick project. I create a forumlar / UI with some text items and textedit items. How can I change the content of the textedit item in my c++ code?

    Thank you for your help.
    BR
    martin

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Its described here
      http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

      I think you are looking for the section with
      QQuickItem item = qobject_cast<QQuickItem>(object);

      1 Reply Last reply
      1
      • M Offline
        M Offline
        msauer75
        wrote on last edited by
        #3

        Hi,

        ok I found it. That meens that I have to create a new QQuickItem for every item, which I want to change it?

        I want to change a item with a id, so I think I need this one?

        @
        QObject rect = object->findChild<QObject>("rect");
        if (rect)
        rect->setProperty("color", "red");
        @

        BR
        martin

        mrjjM 1 Reply Last reply
        0
        • M msauer75

          Hi,

          ok I found it. That meens that I have to create a new QQuickItem for every item, which I want to change it?

          I want to change a item with a id, so I think I need this one?

          @
          QObject rect = object->findChild<QObject>("rect");
          if (rect)
          rect->setProperty("color", "red");
          @

          BR
          martin

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @msauer75

          Hi
          The sample you shown searches for QObject named "rect"

          So yes, you would search for all this way but you can use a function wrapper so its
          very compact.

          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