PyQt Selected row in Table Widget - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: PyQt Selected row in Table Widget (/thread-14513.html) |
PyQt Selected row in Table Widget - rarevesselt - Dec-04-2018 [attachment=502] How can I dynamically select row and get the product id value for the selected product to be passed into the query? def deleteProduct(self): row = self.products_table.currentRow() if row > -1: product_id = (self.products_table.item(row, 0).text(), ) query = session.query(Product).filter(Product.product_id=='product_id').first() session.delete(query) session.commit() #self.dbCursor.execute("""DELETE FROM Main WHERE username=?""", currentUsername) #self.dbConn.commit() self.products_table.removeRow(row) RE: PyQt Selected row in Table Widget - rarevesselt - Dec-06-2018 (Dec-04-2018, 09:45 AM)rarevesselt Wrote: [attachment=502] How can I dynamically select row and get the product id value for the selected product to be passed into the query?def deleteProduct(self): row = self.products_table.currentRow() if row > -1: product_id = (self.products_table.item(row, 0).text(), ) query = session.query(Product).filter(Product.product_id==product_id).first() session.delete(query) session.commit() #self.dbCursor.execute("""DELETE FROM Main WHERE username=?""", currentUsername) #self.dbConn.commit() self.products_table.removeRow(row) Am getting this error : reraise(type(exception), exception, tb=exc_tb, cause=cause) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context context) File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.InterfaceError: <exception str() failed>How can I resolve this error? RE: PyQt Selected row in Table Widget - Axel_Erfurt - Dec-06-2018 what is if row > -1: and the comma in (self.products_table.item(row, 0).text(), ) i would check if there is a selection and remove the comma def deleteProduct(self): if self.products_table.selectionModel().hasSelection(): row = self.products_table.currentRow() product_id = (self.products_table.item(row, 0).text()) query = session.query(Product).filter(Product.product_id=='product_id').first() session.delete(query) session.commit() #self.dbCursor.execute("""DELETE FROM Main WHERE username=?""", currentUsername) #self.dbConn.commit() self.products_table.removeRow(row) RE: PyQt Selected row in Table Widget - rarevesselt - Dec-07-2018 Thanks for your response.This is the working code.Thanks Axel_Erfurt.I removed the comma too. Quote:The row>-1 too does not do anything. def deleteProduct(self): row = self.products_table.currentRow() currentproductid = (self.products_table.item(row, 0).text() ) query = session.query(Product).filter(Product.product_id==str(currentproductid)).first() session.delete(query) session.commit() self.products_table.removeRow(row) |