QML ListView contentHeight not changed when list is cleared



  • I have a QML ListView that is controlled by a C++ class. When I add items to the list (using the C++ class) the contentHeight is changed:

    C++:
    @
    beginInsertRows(QModelIndex(),count() /* starting point */, count() + anItemCount -1);

    // insert some items

    endInsertRows();
    @

    QML:
    @
    ListView {
    id: list
    onContentHeightChanged: { console.log(contentHeight) }
    }
    @

    The content height is now printed whenever I add some items to the ListView.

    But when I remove all items from the list the contentHeight is not changed. I clear the list as follows in C++:

    @
    void ListDataModel::Clear()
    {
    mItems.clear();
    reset();
    }
    @

    The items are cleared from my QML ListView but the contentHeight is not changed. This is a problem because my scrollBar uses the contentHeight of the ListView to show the scrollbar. When the contentHeight is not changed the old scrollbar is visible instead of no scrollbar!

    Any suggestions?



  • This looks like https://bugreports.qt-project.org/browse/QTBUG-16352 which has been fixed for QtQuick 2.0



  • Indeed, that looks like my problem :) I have "fixed" this as follows by changing my Scrollbar:

    @
    BorderImage {
    property variant target
    property string scrollBarState
    source: getImage("scrollbar")
    border {left: 0; top: 3; right: 0; bottom: 3}
    width: 17

        anchors {top: target.top; bottom: target.bottom; right: target.right }
        visible: (track.height == slider.height || target.count==0) ? false : true 
    

    @

    I added the target.count==0 to the visible property.


Log in to reply
 

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