Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Listview dynamic item's scroll problem.
Forum Updated to NodeBB v4.3 + New Features

Listview dynamic item's scroll problem.

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 861 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.
  • G Offline
    G Offline
    ghlab
    wrote on last edited by
    #1

    Hi.
    I coded Listview can show dynamic item using Loader.
    It works fine but when adding ScrollView I found one problem.
    The scroll moves up and down like "this video":http://www.youtube.com/watch?v=7ohx1hNIChA.
    I guess that the problem is occurred by wrong calculated item height.
    How can I resolve this problem?

    Thank you.

    Sample qml
    @import QtQuick 2.0
    import QtQuick.Controls 1.1

    Rectangle {
    width: 360
    height: 360

    ListModel {
        id: listModel
        Component.onCompleted: {
           for(var i = 0; i < 1000; ++i) {
              append({"contents": qsTr("Sample text"),
                         "type": i % 2});
           }
        }
    }
    
    ScrollView {
        anchors.fill: parent
    
        ListView {
            id: listView
            anchors.fill: parent
            model: listModel
            delegate: itemDelegate
        }
    }
    
    Component {
        id: itemDelegate
    
        Item {
            width: listView.width
            height: component.height
    
            Component {
                id: txtComponent
    
                Item {
                    width: listView.width
                    height: txt.height
    
                    Text {
                        id: txt
                        font.pixelSize: 15
                        text: contents
                    }
                }
            }
    
            Component {
                id: imgComponent
    
                Item {
                    width: listView.width
                    height: img.height
    
                    Image {
                        id: img
                        source: "http://qt-project.org/images/qt13a/Qt-logo.png"
                    }
                }
            }
    
            Loader {
                id: component
                sourceComponent: type == 0 ? txtComponent : imgComponent
            }
        }
    }
    

    }
    @

    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