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. ui.qml text object needs to be edited from another .qml file

ui.qml text object needs to be edited from another .qml file

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlui.qmlproperty aliasqt creatorqtquick
6 Posts 2 Posters 1.3k Views
  • 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.
  • T Offline
    T Offline
    texasRanger
    wrote on last edited by
    #1

    I have read a lot on this topic and for some reason can't find one that works (may be user error). I have a program that displays a text box that was created in the .ui.qml file. I want to be able to edit the text from a .qml file and have the changes appear in the .ui.qml file. the ui file is nice for designing with the design mode. However, it does not allow for function calls. So i need to be able to change the text from a .qml file.

    //Display.qml
    
    DisplayFom {
    
    propety alias custom: custom.text
    
    Text {
    id: custom
    text: "Hello World"
    }
    
    
    //DisplayForm.ui.qml
    
    Item {
        id: element
        x: 0
        width: 800
        height: 800
    
        Text {
            id: title
            text: custom
        }
    }
    
    ODБOïO 1 Reply Last reply
    0
    • T texasRanger

      I have read a lot on this topic and for some reason can't find one that works (may be user error). I have a program that displays a text box that was created in the .ui.qml file. I want to be able to edit the text from a .qml file and have the changes appear in the .ui.qml file. the ui file is nice for designing with the design mode. However, it does not allow for function calls. So i need to be able to change the text from a .qml file.

      //Display.qml
      
      DisplayFom {
      
      propety alias custom: custom.text
      
      Text {
      id: custom
      text: "Hello World"
      }
      
      
      //DisplayForm.ui.qml
      
      Item {
          id: element
          x: 0
          width: 800
          height: 800
      
          Text {
              id: title
              text: custom
          }
      }
      
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      hi @texasRanger
      the propety alias sould be in your DisplayForm.ui.qml file

      //DisplayForm.ui.qml

      Item {
          width: 400
          height: 400
      
          property alias textItem: element //<
      
          Text {
              id: element
              x: 188
              y: 193
              text: qsTr("Text")
              font.pixelSize: 12
          }
      }
      
      

      //Display.qml

      DisplayForm {
          textItem.text: "Hello World"
      }
      

      then you can create Display components in other qml files

      example main.qml

      Window {
          id:root
          visible: true
          width: 640
          height: 480
          Display{
              textItem.text: "hi"
          }
      }
      
      1 Reply Last reply
      1
      • T Offline
        T Offline
        texasRanger
        wrote on last edited by texasRanger
        #3

        @LeLev I appreciate your response. Sorry, I'm very new to Qt and qml. So without the Display component in main.qml and if we only had display and display form. Would Display.qml be able to change the text to "Hello World" with the example you gave?

        ODБOïO 1 Reply Last reply
        0
        • T texasRanger

          @LeLev I appreciate your response. Sorry, I'm very new to Qt and qml. So without the Display component in main.qml and if we only had display and display form. Would Display.qml be able to change the text to "Hello World" with the example you gave?

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @texasRanger yes, you can define the text inside Display.qml like i did in the example .you can test it.

          T 1 Reply Last reply
          1
          • ODБOïO ODБOï

            @texasRanger yes, you can define the text inside Display.qml like i did in the example .you can test it.

            T Offline
            T Offline
            texasRanger
            wrote on last edited by texasRanger
            #5

            @LeLev I must be missing something else (whether its a piece of code or knowledge), cause mine still displays the word "Text". All i have are the two files, DisplayForm.ui.qml and Display.qml, and these files are not a part of any project (Did not know if that mattered). Since they are not a part of any project I can't actually run or build these files. So when i make a change in the ui.qml file it updates in real time. Is it supposed to be the same for the .qml file when it makes an edit to the .ui.qml file?

            ODБOïO 1 Reply Last reply
            0
            • T texasRanger

              @LeLev I must be missing something else (whether its a piece of code or knowledge), cause mine still displays the word "Text". All i have are the two files, DisplayForm.ui.qml and Display.qml, and these files are not a part of any project (Did not know if that mattered). Since they are not a part of any project I can't actually run or build these files. So when i make a change in the ui.qml file it updates in real time. Is it supposed to be the same for the .qml file when it makes an edit to the .ui.qml file?

              ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by ODБOï
              #6

              @texasRanger said in ui.qml text object needs to be edited from another .qml file:

              he ui.qml file it updates in real time

              how do you show it on the screen ? with qmlscene tool ?

              if you set textItem.text : "Hello World" inside Display.qml and show it with qmlscene you will see "Hello World".
              but if you show DisplayForm.ui.qml you will still see "Text"

              1 Reply Last reply
              1

              • Login

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