how to EnsureVisible a newly added item on qlistwidget in python?
-
11-02-2021 - |
문제
when i added an item in a qlistwiget and reaches the bottom. A scroll bar appears, how can i ensurevisible an item that was newly added from the qlistwidget? Or how can i get the focus to the last index?
해결책
QListWidget
inherits from QAbstractItemView
, which has the methods you are looking for:
- You can use
QAbstractItemView.scrollTo(ModelIndex index)
, using the index of your newly added item. - Alternatively, since your item is always appended to the end of the list, just call
QAbstractItemView.scrollToBottom()
.
다른 팁
After creating the new QListWidgetItem
, pass it to QListWidget.scrollToItem to ensure that it becomes visible.
Note that scrollToItem
also has a scroll hint parameter that allows fine-tuning of how the item is re-positioned in the list widget.
제휴하지 않습니다 StackOverflow