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. QML ListView contentHeight not changed when list is cleared
QtWS25 Last Chance

QML ListView contentHeight not changed when list is cleared

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.8k Views
  • 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.
  • B Offline
    B Offline
    bkamps
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MartinJ
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bkamps
        wrote on last edited by
        #3

        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.

        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