Searching a record and displaying data in QTableWidget
Unsolved
General and Desktop
-
I'm searching with an id and display the data in QTableWidget. Below is my code, any assistance to check if I;m on track. Thanks
def Get_Summary_Info(self): Staff_Summary_Details_Search = self.ui.Staff_Summary_info_lineEdit.text() if(Summary_Details_Search!=""): cur.execute( " SELECT name,telephone, email FROM personal_info WHERE id=?", [(Summary_Details_Search)]) employees = cur.fetchall() for row_number, employee in enumerate(employees): self.ui.Summary_tableWidget.insertRow(row_number) for column_number, data in enumerate(employee): cell = QtWidgets.QTableWidgetItem(str(employee)) self.ui.Summary_tableWidget.setItem(row_number, column_number, cell) else: QMessageBox.information(self, "Warning", "Search Field Cannot be Empty")
-
You might want use QSqlTableModel at QTableView instead. You can use QSqlTableModel::setFilter() to apply your WHERE clause.