I can figure out how to check if all checkboxes are checked, by iterating over a QListView, like explained here
But is there a way to connect to a function, right at the time of checking an individual box, which also might not be the same as the currently selected object in the QListView? E.g. the equivalent of self.listview.clicked.connect(foo)
Minimal combined with linked example above:
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QWizardPage, QListView
class AppRemovalPage(QWizardPage):
def __init__( self, parent ):
super(AppRemovalPage, self).__init__(parent)
self.setTitle('Apps to Remove')
self.setSubTitle('Listview')
self.list_view = QListView(self)
self.list_view.setMinimumSize(465, 200)
self.isWritten = False
self.model = QtGui.QStandardItemModel(self.list_view)
for line in ('a', 'b', 'c', 'd', 'e'):
self.item = QtGui.QStandardItem(line)
self.item.setCheckable(True)
self.item.setCheckState(QtCore.Qt.Unchecked)
self.model.appendRow(self.item)
self.list_view.setModel(self.model)
self.list_view.clicked.connect(self.getSelectedListItem)
self.list_view.show()
def print_checked_items(self):
for index in range(self.model.rowCount()):
item = self.model.item(index)
if item.checkState() == QtCore.Qt.Checked:
print(item.text(), "was checked")
print("rerun timed script to list checked objects again")
def getSelectedListItem(self):
"""
Gets the name and row of the selected object.
"""
currentSelection = self.list_view.selectedIndexes()
name = None
row = None
index = None
# Set name for currently selected object in listview
for obj_index in currentSelection:
item = self.model.itemFromIndex(obj_index)
row = item.row()
index = self.model.index(row, 0)
name = self.model.data(index)
self.currName = name
self.currRow = row
self.currIndx = index
print(self.currName)
app = QApplication([])
listview = AppRemovalPage(None)
listview.show()
QTimer.singleShot(5000, listview.print_checked_items)
app.exec_()