Python / UI and Layouts / Table Widget
Table Widget
-
Step 1:
self.tableWidget = QTableWidget() self.tableWidget.setRowCount(len(data_list)) self.tableWidget.setColumnCount(3) self.tableWidget.setHorizontalHeaderLabels(["Mobile", "Name", "Action"]) self.i=0 for row in data_list: self.deleteButton = QPushButton("Delete") self.deleteButton.clicked.connect(self.deleteClicked) self.tableWidget.setItem(self.i,0, QTableWidgetItem(row[1])) self.tableWidget.setItem(self.i,1, QTableWidgetItem(row[2])) self.tableWidget.setCellWidget(self.i, 2, self.deleteButton) #self.tableWidget.setColumnWidth(self.i, 150) self.i=self.i+1 self.layout = QVBoxLayout() self.mainMenu() self.layout.addWidget(self.tableWidget) w = QWidget() w.setLayout(self.layout) self.setCentralWidget(w) def deleteClicked(self): button = self.tableWidget.sender() if button: row = self.tableWidget.indexAt(button.pos()).row() mobile =self.tableWidget.item(row,0).text() self.tableWidget.removeRow(row) conn = None conn = sqlite3.connect(os.path.dirname(os.path.realpath(__file__))+'\whatsapp.db') cur = conn.cursor() mobile=347 print(mobile) cur.execute(""" DELETE FROM contact_list WHERE id=? """, (mobile,) ) conn.commit()