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. TextField within ListView
QtWS25 Last Chance

TextField within ListView

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 965 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.
  • J Offline
    J Offline
    justin1122
    wrote on last edited by
    #1

    I have created a listview with a delegate that produces a textfield. The effect is a flickable column of multiple text fields. It seems that Qt repaints these text fields as they appear and disappear from the viewable area which makes the program run a bit sluggish. I've had to place a few hacks to get the value and save it to the corresponding model, which led me thinking that I am perhaps going about this the wrong way. I haven't seen any examples with a textfield inside of a listview, so maybe I should use a different delegate?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      How does your model look like? It should be quite straightforward to save the value to the model no?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        justin1122
        wrote on last edited by
        #3

        This is my model:

        @ListModel {
        id: myModel
        ListElement {
        name: "Speed"
        units: "mm*100/s"
        group: "conveyor"
        mValue: "10"
        mid: 0
        }
        ....@

        and my delegate consist of a TextField with:
        @ onValueChanged: {
        // Save the input
        if(inputText != ""){
        myModel.set(mid, {"mValue": inputText});
        console.log(mid + "==" + inputText)
        }
        }@

        I use "mid" to identify the index and the inputText then to save. I have it working alright, but I couldn't find a way to grab the current delegate index as wel.

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

          Hi,

          Your delegates have access to a special property "index".
          I refer to the link below for more explanation.

          https://qt-project.org/doc/qt-5-snapshot/qtquick-modelviewsdata-modelview.html#models

          But if you do something like, you can see it:

          @ onValueChanged: {
          console.log("index = " + index)
          }
          @

          Changing the value of the model can be done like so:

          @onAccepted: {console.log("accepted"); myModel.set(index, {...})}@

          Also ListView has a currentIndex and currentItem property if you need those.

          Good luck!

          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