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. Binding a TextField to the current TableView item [solved]
Forum Updated to NodeBB v4.3 + New Features

Binding a TextField to the current TableView item [solved]

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

    Hi,

    I'm using the QML desktop-components and want to bind the currently selected row of a TableView to a TextField, so I'm using this code:
    @TextField {
    text: mymodel.get(tableview.currentIndex).myproperty
    }@

    If I change the current item in the TableView, the value of the TextField changes, as expected.
    But if I modify the TextField, the model data does not change! In general, I'd think, that this is possible, because QML uses bindings.
    I think the problem is using a getter here.

    Would it be possible to modify this code to something like
    @
    text: mymodel[tableview.currentIndex].myproperty
    @
    to create a bidirectional binding: so that the model is modified, if the value of the TextField is changed?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      AFAIK, ListModel doesn't support the behavior you need. If you still want to do it you'll have to monitor the change on TextField and call setProperty() on the model, whenever TextField changes.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thisisbhaskar
        wrote on last edited by
        #3

        @text: mymodel.get(tableview.currentIndex).myproperty@

        This creates one directional binding. When ever value of right side expressing changes, value of left side variable is updated with new value. But the other way is not true. When ever text changes, it does not updated model data.
        http://doc.qt.nokia.com/4.7-snapshot/propertybinding.html

        1 Reply Last reply
        0
        • M Offline
          M Offline
          manuelsch
          wrote on last edited by
          #4

          Ok, thanks.
          I added this line, and now it works:
          @onTextChanged: myModel.setProperty(tableview.currentIndex, "myproperty", text)
          @

          1 Reply Last reply
          0
          • L Offline
            L Offline
            loladiro
            wrote on last edited by
            #5

            Good to hear that. Glad I could help.

            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