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]Modifying qml element properties from another qml file
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Modifying qml element properties from another qml file

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

    Here is the problem I'm trying to solve:

    I would like to know how I can access an element inside a certain qml file from other qml files to change its properties, i.e. I have a TextInput element, and I want to clear its content on onButtonClick events located in other qml files.

    Thanks in advance for your help

    /Elnaz ~:>

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

      @
      onButtonClick: {
      myOtherFileId.text = "";
      }
      @

      Is that what you want? It would work is this document is declared as an object with an ID in your "main" file. If it is declared elsewhere, you can still achieve communication, but you need to, for example, pass signals to file where TextInput is declared, and clear it from there in a slot similar to one I've written above.

      (Z(:^

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Elnaz
        wrote on last edited by
        #3

        Thanks for the quick reply. Unfortunately I don,t have it as a declared object in the main.qml so I think I should go for sending signals. I'll try to find out how, and will come back with news on how it went :)

        /Elnaz ~:>

        1 Reply Last reply
        0
        • T Offline
          T Offline
          task_struct
          wrote on last edited by
          #4

          Hi,

          I am not sure if this is want you want but if I understand you rigth this should help you:

          SomeComponent.qml
          @
          Item {

          property alias inputText: txtInput.text
          

          // some QML Items
          // ............

          TextInput {
          id: txtInput
          }
          }
          @

          Then in some other qml file you have:

          Other.qml
          @
          Item {

           Button {
                onbuttonClicked: smCmp.inputText = ""
           }
          
           SomeComponent {
               id: smCmp
           }
          

          }
          @

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          1 Reply Last reply
          0
          • E Offline
            E Offline
            Elnaz
            wrote on last edited by
            #5

            Well, I just made the signal solution work.
            I just added a signal to the qml file (e.g. called Menu)containing the TextInput element, like this:
            @
            signal clearText()
            onClearText: textInput.text =" "
            @

            Now, if for example I have a declared object of the Menu qml file with id:myMenu, I can emit the clearText() signal to get the TextInput cleared from wherever I want, like this:

            @myMenu.clearText()@

            I'm not sure, but I guess the second solution (by task_struct) won't work in my case, because the object is declared somewhere else than where I want to raise the clearText() event.

            Thanks for your suggestions anyhow :)

            /Elnaz ~:>

            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