Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal when an item is added or removed to a QListWidget

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?

like image 268
NewGuy Avatar asked Dec 12 '22 00:12

NewGuy


1 Answers

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

like image 129
mdurant Avatar answered Jan 21 '23 09:01

mdurant