Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Visible items of QML ListView



  • Hi! I'm trying to get all visible items (indexes) of QML ListView, but i'm not shure how to realize this functionality. Maybe is some working approach exists? Thank you in advance.



  • Guys, what do you think about method like that?

    function populateVisibleItems() {
            var aStartPos = chatView.contentY;
            var aFinishPos = aStartPos + chatView.height;
            var aStep = 15;
    
            var aCurrentItem, aPreviousItem;
    
            for( var aCurrPos = aStartPos; aCurrPos <= aFinishPos; aCurrPos += aStep ) {
                aCurrentItem = chatView.itemAt( 0, aCurrPos );
                if( aCurrentItem && aCurrentItem.objectName === "message_item" && aPreviousItem !== aCurrentItem ) {
                    console.log( aCurrentItem.text + " is visible" );
                    // do some stuff (push into array, etc..)
                }
                aPreviousItem = aCurrentItem;
            }
        }
    

Log in to reply