I have built a program in Python that runs a GUI and displays various tables. The format I have been using works so far, but now I have to add a checkbox column to the table, and i really don't know what to do. My teacher doesn't know how to use PyQt. The table has a name field, an email field, and a check field.
here is the table with checkbox I have currently:
def trigger_file_delete_student(self):
self.label_title.setText("Students list")
self.tableName = "StudentList"
self.cur.execute("""SELECT FullName, EmailAddress FROM StudentProfile""")
self.all_data = self.cur.fetchall()
self.table.setRowCount(len(self.all_data))
self.table.setColumnCount(3)
self.tableFields = ['Full name', 'Email address', "Check"]
self.table.setHorizontalHeaderLabels(self.tableFields)
self.chkBoxItem = QtGui.QTableWidgetItem()
self.chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
self.chkBoxItem.setCheckState(QtCore.Qt.Unchecked)
for i, item in enumerate(self.all_data):
FullName = QtGui.QTableWidgetItem(str(item[0]))
EmailAddress = QtGui.QTableWidgetItem(str(item[1]))
self.table.setItem(i, 0, FullName)
self.table.setItem(i, 1, EmailAddress)
self.table.setItem(i, 2, self.chkBoxItem)
Here is a screenshot of what happens when run:
How do I get it so that when a button is clicked, all the names that are ticked get added to a list?
I only have a couple of other tables that I have set up, so if you think it would be better for me to try this in a different table format to make it easier, I can easily change to that. I have never done any work on tables in PyQt GUIs before, so I really have no idea how I am meant to do things.
Aucun commentaire:
Enregistrer un commentaire