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. Problem with ListView dynamic height

Problem with ListView dynamic height

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

    I am having a ListView and have applied a scroll bar on it. The scrollbar is working fine if each row is of same height. But when the heights of rows vary then scrollbar starts behaving unexpectedly. I found out that the ListView redraws its elements while flicking. So the contentHeight changes it's value in case of different row heights while scolling. I am using Qt 4.7 and QtQuick 1.0 versions of Qt and QML respectively.

    @Item {
    id: myItem
    property variant items

    ListView {
    id: list
    anchors.fill: parent
    clip: true
    model: items
    delegate: trackDelegate
    focus: true
    boundsBehavior: Flickable.StopAtBounds
    }
    }

    ScrollBar {
    id: verticalScrollBar
    target: list
    clip: true
    }
    }

    And scroll bar code is
    // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
    import Qt 4.7
    Item {
    property variant target
    width: 8
    anchors.top: target.top
    anchors.bottom: target.bottom
    anchors.margins: 1
    anchors.rightMargin: 2
    anchors.bottomMargin: 2
    anchors.right: target.right
    visible: (track.height == slider.height) ? false : true
    Image {
    id: scrollPath
    width: 2
    anchors.top: parent.top
    anchors.bottom: parent.bottom
    anchors.horizontalCenter: parent.horizontalCenter
    source: "qrc:/resources/buttons/slider2.png"
    }
    Item {
    anchors.fill: parent
    Timer {
    property int scrollAmount
    id: timer
    repeat: true
    interval: 20
    onTriggered: {
    target.contentY = Math.max(0, Math.min(target.contentY + scrollAmount,
    target.contentHeight - target.height));
    }
    }
    Item {
    id: track
    anchors.top: parent.top
    anchors.topMargin: 1
    anchors.bottom: parent.bottom
    width: parent.width
    MouseArea {
    anchors.fill: parent
    onPressed: {
    timer.scrollAmount = target.height * (mouseY < slider.y ? -1 : 1)
    timer.running = true;
    }
    onReleased: {
    timer.running = false;
    }
    }
    Image {
    id:slider
    anchors.horizontalCenter: parent.horizontalCenter
    source: "qrc:/resources/buttons/slider.png"
    width: parent.width
    height: Math.min(target.height / target.contentHeight * track.height, track.height) < 20 ? 20 : Math.min(target.height / target.contentHeight * track.height, track.height)
    y: target.visibleArea.yPosition * track.height
    MouseArea {
    anchors.fill: parent
    drag.target: parent
    drag.axis: Drag.YAxis
    drag.minimumY: 0
    drag.maximumY: track.height - height
    onPositionChanged: {
    if (pressedButtons == Qt.LeftButton) {
    target.contentY = slider.y * target.contentHeight / track.height;
    }
    }
    }
    }
    }
    }
    }

    @

    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