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. TextEdit on ListView don't keep text after scrolling.
Forum Updated to NodeBB v4.3 + New Features

TextEdit on ListView don't keep text after scrolling.

Scheduled Pinned Locked Moved QML and Qt Quick
15 Posts 4 Posters 4.1k 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
    MathArtist
    wrote on last edited by
    #1

    Hi everybody!
    I'm having an issue with my QtQuick / QML app.
    It happens on desktop an android.

    I have list of fields to be completed with data.
    The fields are listed on a ListView and each one have a TextEdit Element for input.

    While completing the fields one by one the list view is scrolled.

    The problem is: when the TextEdit is out of the list visible area, is loose the text and it became empty again.

    Video of the problem: "Link":https://www.youtube.com/watch?v=1sHKnNZLzhs

    Here, a minimal example reproducing the described behavior.

    In this example the text filled in the first fields is lost after scrolling to the bottom and get to the top again.

    @
    import QtQuick 2.2
    import QtQuick.Controls 1.2

    ApplicationWindow {
    id: applicationWindow1
    visible: true
    width: 200
    height: 200
    title: qsTr("TextEdit on ListView Test")

    ListView {
        id: listView1
        x: 286
        width: 110
        boundsBehavior: Flickable.StopAtBounds
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottomMargin: 0
        anchors.topMargin: 0
        anchors.bottom: parent.bottom
        anchors.top: parent.top
        clip: true
        model: ListModel {
            ListElement {
                name: "Grey"
                colorCode: "grey"
            }
    
            ListElement {
                name: "Red"
                colorCode: "red"
            }
    
            ListElement {
                name: "Blue"
                colorCode: "blue"
            }
    
            ListElement {
                name: "Green"
                colorCode: "green"
            }
            ListElement {
                name: "Grey"
                colorCode: "grey"
            }
    
            ListElement {
                name: "Red"
                colorCode: "red"
            }
    
            ListElement {
                name: "Blue"
                colorCode: "blue"
            }
    
            ListElement {
                name: "Green"
                colorCode: "green"
            }
            ListElement {
                name: "Grey"
                colorCode: "grey"
            }
    
            ListElement {
                name: "Red"
                colorCode: "red"
            }
    
            ListElement {
                name: "Blue"
                colorCode: "blue"
            }
    
            ListElement {
                name: "Green"
                colorCode: "green"
            }
            ListElement {
                name: "Grey"
                colorCode: "grey"
            }
    
            ListElement {
                name: "Red"
                colorCode: "red"
            }
    
            ListElement {
                name: "Blue"
                colorCode: "blue"
            }
    
            ListElement {
                name: "Green"
                colorCode: "green"
            }
            ListElement {
                name: "Grey"
                colorCode: "grey"
            }
    
            ListElement {
                name: "Red"
                colorCode: "red"
            }
    
            ListElement {
                name: "Blue"
                colorCode: "blue"
            }
    
            ListElement {
                name: "Green"
                colorCode: "green"
            }
        }
        delegate: Item {
            width: 100
            height: 40
                Rectangle {
                    width: 100
                    height: 40
                    color: colorCode
                    TextEdit {
    
                        font.pointSize: 23
                        anchors.fill: parent
    
                        font.bold: true
                        anchors.verticalCenter: parent.verticalCenter
                    }
                }
        }
    }
    

    }
    @

    Is this a bug?
    Do I need to set something else to make it persistent?
    Should I make copy of the text after editing finished and put it back when it became visible as a normal workflow?

    Best Regards

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dasRicardo
      wrote on last edited by
      #2

      Can't reproduce on linux qt 5.3.2 and android emulator

      @
      ListView {
      id: listView1
      x: 286
      width: 110
      boundsBehavior: Flickable.StopAtBounds
      anchors.horizontalCenter: parent.horizontalCenter
      anchors.bottomMargin: 0
      anchors.topMargin: 0
      anchors.bottom: parent.bottom
      anchors.top: parent.top
      clip: true
      model: ListModel {
      ListElement {
      name: "Grey"
      colorCode: "grey"
      }

                  ListElement {
                      name: "Red"
                      colorCode: "red"
                  }
      
                  ListElement {
                      name: "Blue"
                      colorCode: "blue"
                  }
      
                  ListElement {
                      name: "Green"
                      colorCode: "green"
                  }
                  ListElement {
                      name: "Grey"
                      colorCode: "grey"
                  }
      
                  ListElement {
                      name: "Red"
                      colorCode: "red"
                  }
      
                  ListElement {
                      name: "Blue"
                      colorCode: "blue"
                  }
      
                  ListElement {
                      name: "Green"
                      colorCode: "green"
                  }
                  ListElement {
                      name: "Grey"
                      colorCode: "grey"
                  }
      
                  ListElement {
                      name: "Red"
                      colorCode: "red"
                  }
      
                  ListElement {
                      name: "Blue"
                      colorCode: "blue"
                  }
      
                  ListElement {
                      name: "Green"
                      colorCode: "green"
                  }
                  ListElement {
                      name: "Grey"
                      colorCode: "grey"
                  }
      
                  ListElement {
                      name: "Red"
                      colorCode: "red"
                  }
      
                  ListElement {
                      name: "Blue"
                      colorCode: "blue"
                  }
      
                  ListElement {
                      name: "Green"
                      colorCode: "green"
                  }
                  ListElement {
                      name: "Grey"
                      colorCode: "grey"
                  }
      
                  ListElement {
                      name: "Red"
                      colorCode: "red"
                  }
      
                  ListElement {
                      name: "Blue"
                      colorCode: "blue"
                  }
      
                  ListElement {
                      name: "Green"
                      colorCode: "green"
                  }
              }
              delegate: Rectangle {
                          width: 100
                          height: 40
                          color: colorCode
                          TextEdit {
                              color: '#ffffff'
                              font.pointSize: 23
                              anchors.fill: parent
      
                              font.bold: true
                              anchors.verticalCenter: parent.verticalCenter
                          }
              }
          }
      

      @

      **Sorry for my english :)

      PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

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

        Hi dasRicardo,

        with the code posted by me, the problem persist in linux Qt 5.3.1 , 5.3.2 and 5.4.0(Beta) and android same versions.
        I have not tested on another OS yet.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dasRicardo
          wrote on last edited by
          #4

          OK, and with my code the same? I have remove the Item around the Rectangle, i have no idea why you need it?

          **Sorry for my english :)

          PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MathArtist
            wrote on last edited by
            #5

            I have tried your code too.
            The rectangles where only for visual separation.

            After writing some text in all the TextEdit elements an playing a little with the scroll the content of many of them just became empty.

            And the text change event is not rised when this happen.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MathArtist
              wrote on last edited by
              #6

              I added a "video":https://www.youtube.com/watch?v=1sHKnNZLzhs of the problem.
              I also tried on macosx and get the same behavior.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dasRicardo
                wrote on last edited by
                #7

                Hmmm, sounds like a bug i havn't test it so massivly. Whats your goal for this construct? What's your ui idea behind this?

                **Sorry for my english :)

                PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MathArtist
                  wrote on last edited by
                  #8

                  I added a video of the problem in the first post of this thread.
                  I also tried on macosx and get the same behavior.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dasRicardo
                    wrote on last edited by
                    #9

                    Can't reproduce this sorry, maybe graphics driver bug?

                    **Sorry for my english :)

                    PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MathArtist
                      wrote on last edited by
                      #10

                      [quote author="dasRicardo" date="1412026473"]Hmmm, sounds like a bug i havn't test it so massivly. Whats your goal for this construct? What's your ui idea behind this?[/quote]

                      My goal is to make a survey app. so you define some questions. the list say question and have some space for input the data.
                      Like name, last name, age, address, opinion... etc etc

                      the real app is more complex but for the forum I just make a simple test code with the minimal elements to reproduce the problem.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        MathArtist
                        wrote on last edited by
                        #11

                        [quote author="dasRicardo" date="1412026795"]Can't reproduce this sorry, maybe graphics driver bug?[/quote]

                        I think this is not a graphic driver issue, because I have same result on Mac with Nvidia graphics, suse linux with intel graphics, and various android phones and tablet from different vendors.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dasRicardo
                          wrote on last edited by
                          #12

                          Hmm, but i think a list is the wrong component for you. Have you try to simply add some input into a flickable container and test if it produce the same result?

                          **Sorry for my english :)

                          PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

                          1 Reply Last reply
                          0
                          • H Offline
                            H Offline
                            hmuelner
                            wrote on last edited by
                            #13

                            From the documentation of ListView ("http://qt-project.org/doc/qt-5/qml-qtquick-listview.html#delegate-prop":http://qt-project.org/doc/qt-5/qml-qtquick-listview.html#delegate-prop):

                            Note: Delegates are instantiated as needed and may be destroyed at any time. They are parented to ListView's contentItem, not to the view itself. State should never be stored in a delegate.

                            You should map the text of your TextEdit to a property of the ListElements in your ListModel.

                            Helmut Mülner

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              Torgeir
                              wrote on last edited by
                              #14

                              The bug is in your delegate. Documentation for ListView says:

                              bq. Delegates are instantiated as needed and may be destroyed at any time. They are parented to ListView's contentItem, not to the view itself. State should never be stored in a delegate.

                              When your delegate contains a TextEdit and you don't store the edited text somewhere, it will be lost when the delegate is destroyed/recreated.

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                MathArtist
                                wrote on last edited by
                                #15

                                Thanks, for the info.

                                What can be a good workarround or a proper workflow for my app?

                                Suggestions are welcome.

                                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