Equivalent to AlignBottom for ListView?



  • Hi, there is this ListView nurtured by a dynamic model that, ideally, should start placing the items in the bottom, piling them up as soon as there is more. In the ListView docs there is a mention to ListView.Vertical, but apparently it is assumed that the list will always grow from top to bottom. Looking at Flickable or Item docs I couldn't find anything either.

    Is there a way to obtain a behavior similar to Text's "verticalAlignment: Text.AlignBottom"?


  • Moderators

    You could use a blank item the height of your viewable area as your ListView::header to pad downward, append to your model, and then call ListView::positionViewAtEnd().



  • Wow, I hadn't thought of solving this problem this way. Thank you!

    Now... I'm still stuck in the implementation since I'm quite new to applying methods. The header is fine, but I must be doing something with the function because the items still are listed from top to bottom. This is the basic structure of the code, see the attempts of adding the function at the end:

    @
    Page {
    id: ficsSeekGame
    ...

    Rectangle {
        id: seekListWindow
    

    ...

        ListView {
            id: seekList
            header: seekListHeader 
            model: gameAdvertisements
            delegate:
    
                Item {
                id: listItem
    
                Rectangle {
                    id: gameData
    

    ...
    }

                    MouseArea {
                        id: mouseArea
                        anchors.fill: parent
                        onClicked: {
                            confirmGame.open();
                        }
    

    ...
    }
    }
    }
    }
    }

    Component {
        id: seekListHeader
    }
    

    ...

    // Component.onCompleted: positionViewAtEnd() why this doesn't work?
    // Component.onCompleted: positionViewAtIndex(count - 1, ListView.Beginning) this doesn't work either?
    

    ...
    }@

    fwiw you can see this code in context at http://gitorious.org/miniature/miniature/blobs/master/src/frontend/SeekGame.qml



  • From #qt-qml:

    <mikhas> hey, having a problem with ListView's
    appending items to it, and the moment the items are out of the visible area, the signal handlers such as ListView.onAdd dont get called any more
    <special> mikhas: that's expected; ListView only creates delegates for visible items (and a small buffer that might be visible soon).
    <mikhas> …
    <special> If you want to react to additions, connect to the signals of the model
    <mikhas> ok
    <mikhas> special, hm, and how? I mean, what is the type of a model in a ListView?
    <special> is your model a QAbstactItemModel?
    <mikhas> yes
    otherwise, I cant dynamically append things
    <special> right; then you can use something like Connections { target: view.model; onRowsInserted: console.log(start, end) }
    <mikhas> ok
    would be nice if that was to be found in the docs
    current ListView doc doesnt mention those details
    like, a ListView signal not being emitted because of delegates only being created for visible range
    <special> technically, it's not a ListView signal; it's an attached signal on the delegate from ListView
    <mikhas> special, works
    really, this should be in docs
    it was not clear to me why such useful looking function such as ListView.positionAtEnd wouldnt work



  • But now it also repositions the view while we are trying to pan the view. What we eventually need is to disrupt that reposition handling upon manual panning, probably with a cooldown of some sort.



  • Thanks! Please upload the new version and I will keep fighting with these methods.



  • Hi,

    For reference, there is a suggestion for official support for this in the system (and it's something we'd like to implement), at "QTBUG-16376":https://bugreports.qt.nokia.com/browse/QTBUG-16376

    Regards,
    Michael



  • Thanks for the pointer. Added my vote. :)



  • [quote author="mikhas" date="1313532737"]
    really, this should be in docs
    it was not clear to me why such useful looking function such as ListView.positionAtEnd wouldnt work[/quote]

    A little contribution to the solution of this problem: http://developer.qt.nokia.com/doc/qt-4.7/qml-listview.html#comments



  • I think the comment could be more helpful, if it actually contained a bit of code that will make sure the newly added item becomes visible. Logging to console isn't going to help there.



  • This is my first note ever to the docs and I'm the non-expert in this thread. :) I just copy-pasted from the posts above thinking that anybody could edit the notes to improve them, like in a wiki (is this true or is this only limited to admins?). Sorry, I'm doing my best here. Thanks for your comments!



  • I did not mean to discourage you from contributing to the docs. However, if you have not come further than the code you posted yet, then perhaps the route will not even work. If I now just read the comment, I don't really see a solution, just a possible beginning of one.

    I think that others can modify and improve on your comment. However, I would like to encourage you to further develop the comment as your solution becomes more complete.

    Thanks for contributing your insights to the documentation!



  • I "posted":http://developer.qt.nokia.com/doc/qt-4.7/qml-listview.html#comments better example showing the code structure to follow and a link to the only "real example":http://gitorious.org/miniature/miniature/blobs/master/src/frontend/SeekGame.qml I have at hand today. I was able to test it today and see it working in our MeeGo Harmattan project and the N9. I guess a clean example without external dependencies would run just anywhere with Qt Quick.

    Andre, thank you for your encouragement - and I mean this. :)

    [EDIT: fixed link, Volker]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.