PyQt, Open a Table when a row is selected populating it with the row values - 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, Open a Table when a row is selected populating it with the row values (/thread-14711.html) Pages:
1
2
|
RE: PyQt, Open a Table when a row is selected populating it with the row values - rarevesselt - Dec-17-2018 (Dec-17-2018, 12:08 PM)Axel_Erfurt Wrote: You create the database yourself? Yes, I have a file for that in user.py for the database. here is the file.I mistakenly copied the wrong one-product.py import sqlalchemy from sqlalchemy import exists from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import DateTime,ForeignKey,Boolean from sqlalchemy.orm import relationship,backref from datetime import datetime Base = declarative_base() class User(Base): __tablename__ = 'users' user_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True) name = sqlalchemy.Column(sqlalchemy.String(35), nullable=False) password = sqlalchemy.Column(sqlalchemy.String(35), nullable=False) email = sqlalchemy.Column(sqlalchemy.String(35)) contact = sqlalchemy.Column(sqlalchemy.String(50)) def __repr__(self): return "<User(name='%s',password='%s',contact='%s', email='%s')>" % (self.name,self.password,self.contact, self.email) class Product(Base): __tablename__ = 'products' product_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True) product_name = sqlalchemy.Column(sqlalchemy.String(35), nullable=False) inventory_received = sqlalchemy.Column(sqlalchemy.String(35), nullable=False) starting_inventory = sqlalchemy.Column(sqlalchemy.String(35), nullable=False) inventory_on_hand = sqlalchemy.Column(sqlalchemy.String(35)) minimum_required = sqlalchemy.Column(sqlalchemy.String(50)) updated_on = sqlalchemy.Column(DateTime(),default=datetime.now()) Created_on = sqlalchemy.Column(DateTime(),default=datetime.now()) user = relationship('User',backref=backref('products',order_by=product_id)) user_id = sqlalchemy.Column(sqlalchemy.Integer, ForeignKey('users.user_id')) def __repr__(self): return "<Product(product_name='%s',starting_inventory ='%s',inventory_received ='%s',inventory_on_hand='%s', minimum_required='%s')>" % (self.product_name,self.starting_inventory,self.inventory_on_hand, self.minimum_required,self.inventory_received) engine = sqlalchemy.create_engine("sqlite:///user.db", echo='debug') Base.metadata.create_all(engine) DBsession = sqlalchemy.orm.sessionmaker(bind=engine) session = DBsession() RE: PyQt, Open a Table when a row is selected populating it with the row values - Axel_Erfurt - Dec-17-2018 Ok, it creates a database with no entries. If there are entries then you want to fill the ComboBoxes? Or the table? I have a DB Viewer on github that shows how to load a database into QTableWidget RE: PyQt, Open a Table when a row is selected populating it with the row values - rarevesselt - Dec-18-2018 (Dec-17-2018, 07:15 PM)Axel_Erfurt Wrote: Ok, it creates a database with no entries.After the the comboBoxes are filled correctly it will saved in QtableWidget in the database. There are entries in the database in QtableWidget. The columns are product_id,product_name,inventory_received,starting_inventory,product_price and values for each rows.The content of my database user.db is shown in the file but I intended to add price. I have three comboboxes first comboBox is product id second comboboxes is product_name third comboBoxes is price. I want the second Combobox to list all the product.That is working perfectly. I want the first comboBox to reflect the product_id of the selected product_name. I want the third comboBox to reflect the price of the selected product_name. How can I achieve this behavior?I have checked out your work on GitHub.But, I am not getting the database to work on my side even when add a database on my system into the path. RE: PyQt, Open a Table when a row is selected populating it with the row values - Axel_Erfurt - Dec-18-2018 your user.db has no column for product price, you want get it from the tableWidget? RE: PyQt, Open a Table when a row is selected populating it with the row values - rarevesselt - Dec-18-2018 Yes,I intend to add price to my table later but as I have said I need help on how to add items to my comboBoxes from the database such that once, I change value in( Product_name) one comboBox other comboBoxes(product_id) and possibly product_price will change into values in the database.I will update with full code later. RE: PyQt, Open a Table when a row is selected populating it with the row values - Axel_Erfurt - Dec-18-2018 You mean somethig like that? video Download Project RE: PyQt, Open a Table when a row is selected populating it with the row values - rarevesselt - Dec-19-2018 No,I mean product_name_box will be a list of all products ,but when a pick a product like Maclean the product_id change to 1 and price to 200.Likewise for all other products.When I press value comboBox the first item is added to Cart Table.I have added a picture what I want.Really appreciate your effort Azel_Efurt.Once I get this basic features all other features can be added. The table widget in the link is cart table https://www.dropbox.com/s/qfou2iuyqw266lv/Screen%20Shot%202018-12-19%20at%2010.03.42%20AM.png?dl=0 RE: PyQt, Open a Table when a row is selected populating it with the row values - rarevesselt - Dec-19-2018 (Dec-18-2018, 06:17 PM)Axel_Erfurt Wrote: You mean somethig like that? Thank so much.I can see your code so worked well.Thanks for the help.I will update with the other features.You have solved it.Thanks once again Azel_ErFurt and others. RE: PyQt, Open a Table when a row is selected populating it with the row values - rarevesselt - Mar-30-2019 [attachment=594] (Dec-19-2018, 06:23 PM)rarevesselt Wrote:(Dec-18-2018, 06:17 PM)Axel_Erfurt Wrote: You mean somethig like that? The image I added is what I end up having.But,I need help on it.When I changed the quantity of product from 1 to another number, I want the table to update automatically.How can I do that? My second interest is how can I make multiple users to operate the UI simultaneously. This is function I used; def your_function(self): self.row = self.Products_table.currentRow() self.currentproduct = (self.Products_table.item(self.row, 0).text() ) self.currentprice = (self.Products_table.item(self.row,1).text() ) ordereditems = QtGui.QTableWidgetItem() row = self.ordereditems.currentRow() numRows = self.ordereditems.rowCount() self.ordereditems.insertRow(numRows) self.total = 0.0 self.items ={} self.ordereditems.setItem(numRows, 0, QtGui.QTableWidgetItem(self.currentproduct)) self.ordereditems.setItem(numRows, 1, QtGui.QTableWidgetItem(str(self.currentprice))) self.ordereditems.setItem(numRows, 2, QtGui.QTableWidgetItem("1")) for numRows in range(numRows+1): self.ordereditems.setItem(numRows, 2, QtGui.QTableWidgetItem(str(self.currentquantity))) self.currentprice =float(self.ordereditems.item(numRows,1).text() ) amount = float(self.currentprice) * float(self.currentquantity) self.ordereditems.setItem(numRows, 3, QtGui.QTableWidgetItem(str(amount))) self.total += amount self.totallinedit.setText(str(self.total)) self.items = {str(self.currentproduct):self.currentquantity} self.items.update({str(self.currentproduct):self.currentquantity}) |