I dynamically add and remove items to a QListWidget based on user selections elsewhere in the application. Is there a signal that is emitted when items are added or removed to a QListWidget? The signals that I see in the documentation doesn't mention anything for Add or Remove. The rest of the signals are for when individual items are interacted with.
How can I be notified when an item is added to my QListWidget?
A very simple example:
from PyQt4.QtGui import *
import sys
app = QApplication(sys.argv)
listWidget = QListWidget()
for i in range(10):
item = QListWidgetItem("Item %i" % i)
listWidget.addItem(item)
# ^^^ This is what I want a signal on
listWidget.show()
sys.exit(app.exec_())
What signal can I utilize to capture that addItem
event?
You need to get hold of the implied model object within the widget:
model = listWidget.model()
This has a rowsInserted
signal that you can connect. See http://doc.qt.io/qt-4.8/qabstractlistmodel-members.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With