QListWidget moving to end of list automatically

12,274

Solution 1

listWidget->scrollToBottom() would work

Solution 2

Should work with scrollToItem().

Share:
12,274
cftmon
Author by

cftmon

Updated on June 13, 2022

Comments

  • cftmon
    cftmon almost 2 years

    I have a QListWidget that has many items added to it, however i want the QListWidget to auto-scroll to the last item everytime a new item is added to it.Is this even possible?

  • Troyseph
    Troyseph about 9 years
    Could you conditionally scrollToBottom() only if it is currently at the bottom?
  • MarSoft
    MarSoft about 3 years
    This won't work for the item you have just added. Or more precisely, it won't work reliably. Often by the time you added a new item, the list view does not yet know about its presence and hence cannot scroll to it.
  • MarSoft
    MarSoft about 3 years
    You can check that by accessing scrollbar widget: scrollbar = myListView.verticalScrollBar(); if(scrollbar == NULL || scrollbar.value() == scrollbar.maximum()) { addItem(); myListView.scrollToBottom(); } else { addItem(); } Here we check if scrollbar exists at all (just to be safe), and if it is missing or we are already at bottom then we do scroll after adding item. Otherwise we just add item without scrolling.