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. ListView ignores `displayMarginBeginning: 0`?
Forum Updated to NodeBB v4.3 + New Features

ListView ignores `displayMarginBeginning: 0`?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 239 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by patrickkidd
    #1

    I initialize ListView.contentY to initially hide the header using contentY: 0 so that you only see it if you swipe down, like in iOS Mail. But ListView seams to ignore displayMarginBeginning: 0 and scrolls to reveal the header when currentIndex is set to 0 even when the first item delegate is completely in view.

    Is there a way to prevent this?

    import QtQuick 2.5
    import QtQuick.Layouts 1.12
    
    ListView {
        id: root
        header: Rectangle {  color: 'red'; height: 40; width: parent.width }
        displayMarginBeginning: 0
        delegate: Item {
            width: parent.width
            height: 50
            RowLayout {
                anchors.fill: parent
                Text { text: name }
                Text { text: cost }
            }
            Rectangle {
                color: index == root.currentIndex ? '#aa0000ff' : 'transparent'
                anchors.fill: parent
            }
        }
    
        // will scroll to ensure item is visible, but                                                                                                                                                               
        // ignores displayMarginBeginning for first item                                                                                                                                                            
        Timer {
    	running: true;
            interval: 1000;
    	repeat: true
            onTriggered: {
                if(currentIndex == 0)
    	        currentIndex = 5;
                else
                    currentIndex = 0;
            }
        }
    
        model: ListModel {
            ListElement { name: "Apple"; cost: 2.45 }
            ListElement { name: "Orange"; cost: 3.25 }
            ListElement { name: "Banana"; cost: 1.95 }
            ListElement { name: "Apple"; cost: 2.45 }
            ListElement { name: "Orange"; cost: 3.25 }
            ListElement { name: "Banana"; cost: 1.95 }
        }
    }
    

    https://alaskafamilysystems.com/

    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