Python Forum
PyQt, Open a Table when a row is selected populating it with the row values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt, Open a Table when a row is selected populating it with the row values
#1
I am trying to learn how to build a Simple POS system.I want to know if it possible to open a table when a Product is selected and additem button is clicked in the table attached.How can I do that?I want the table to be on the same main page with table attached.

Attached Files

Thumbnail(s)
   
Reply
#2
In PyQt5 you can use a SIGNAL in a row that opens a form with your table,
or add a button to a cell in the row and open the sub-form with a table,
or place a table in a cell (I have to try this)
Can you be more specific.
Reply
#3
(Dec-14-2018, 07:29 PM)starglider Wrote: In PyQt5 you can use a SIGNAL in a row that opens a form with your table,
or add a button to a cell in the row and open the sub-form with a table,
or place a table in a cell (I have to try this)
Can you be more specific.
I want to open the product cart beside product table without opening a new window.
I want product cart to be display only when I select a product and click on additem.
Is it possible for me to get that behavior?How can I do that?

This is product cart.py
and the product table is the image added before
from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.setEnabled(True)
        Dialog.resize(1280, 776)
        self.comboBox = QtGui.QComboBox(Dialog)
        self.comboBox.setGeometry(QtCore.QRect(330, 190, 104, 41))
        self.comboBox.setMaximumSize(QtCore.QSize(16777215, 50))
        self.comboBox.setEditable(True)
        self.comboBox.setObjectName(_fromUtf8("comboBox"))
        self.comboBox_3 = QtGui.QComboBox(Dialog)
        self.comboBox_3.setGeometry(QtCore.QRect(430, 190, 291, 41))
        self.comboBox_3.setEditable(True)
        self.comboBox_3.setObjectName(_fromUtf8("comboBox_3"))
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(720, 190, 113, 31))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.lineEdit_2 = QtGui.QLineEdit(Dialog)
        self.lineEdit_2.setGeometry(QtCore.QRect(830, 190, 113, 31))
        self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
        self.comboBox_4 = QtGui.QComboBox(Dialog)
        self.comboBox_4.setGeometry(QtCore.QRect(950, 190, 160, 40))
        self.comboBox_4.setEditable(True)
        self.comboBox_4.setObjectName(_fromUtf8("comboBox_4"))
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(830, 140, 113, 32))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.pushButton_2 = QtGui.QPushButton(Dialog)
        self.pushButton_2.setGeometry(QtCore.QRect(960, 140, 113, 32))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.label = QtGui.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(339, 170, 71, 20))
        self.label.setObjectName(_fromUtf8("label"))
        self.label_2 = QtGui.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(479, 170, 101, 20))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.label_3 = QtGui.QLabel(Dialog)
        self.label_3.setGeometry(QtCore.QRect(740, 170, 60, 16))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_4 = QtGui.QLabel(Dialog)
        self.label_4.setGeometry(QtCore.QRect(860, 170, 60, 16))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(Dialog)
        self.label_5.setGeometry(QtCore.QRect(990, 170, 60, 16))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.line = QtGui.QFrame(Dialog)
        self.line.setGeometry(QtCore.QRect(330, 160, 781, 16))
        self.line.setFrameShape(QtGui.QFrame.HLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName(_fromUtf8("line"))
        self.line_2 = QtGui.QFrame(Dialog)
        self.line_2.setGeometry(QtCore.QRect(330, 120, 781, 16))
        self.line_2.setFrameShape(QtGui.QFrame.HLine)
        self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_2.setObjectName(_fromUtf8("line_2"))
        self.line_3 = QtGui.QFrame(Dialog)
        self.line_3.setGeometry(QtCore.QRect(330, 240, 781, 16))
        self.line_3.setFrameShape(QtGui.QFrame.HLine)
        self.line_3.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_3.setObjectName(_fromUtf8("line_3"))
        self.tableWidget = QtGui.QTableWidget(Dialog)
        self.tableWidget.setGeometry(QtCore.QRect(320, 260, 771, 271))
        self.tableWidget.setRowCount(1)
        self.tableWidget.setColumnCount(5)
        self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
        self.pushButton_3 = QtGui.QPushButton(Dialog)
        self.pushButton_3.setGeometry(QtCore.QRect(840, 280, 113, 32))
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.pushButton_4 = QtGui.QPushButton(Dialog)
        self.pushButton_4.setGeometry(QtCore.QRect(960, 280, 113, 32))
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
        self.pushButton.setText(_translate("Dialog", "clear", None))
        self.pushButton_2.setText(_translate("Dialog", "save", None))
        self.label.setText(_translate("Dialog", "product_id", None))
        self.label_2.setText(_translate("Dialog", "Product_name", None))
        self.label_3.setText(_translate("Dialog", "price", None))
        self.label_4.setText(_translate("Dialog", "quantity", None))
        self.label_5.setText(_translate("Dialog", "value", None))
        self.pushButton_3.setText(_translate("Dialog", "Edit", None))
        self.pushButton_4.setText(_translate("Dialog", "delete", None))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())
Reply
#4
Quote:self.comboBox.setMaximumSize(16777215, 50)

16777215 ???

If you want a fixed width for the first combobox use

self.comboBox.setFixedWidth(100)


Quote:self.tableWidget.setGeometry(QtCore.QRect(320, 260, 771, 271))
(and all the other geometry)

why QtCore.QRect( ?

just use

self.tableWidget.setGeometry(10, 260, 771, 271)

Normally it is better to make a layout instead of always using "setGeometry".

I have no Qt4, did a test in Qt5 with your code.
I have renamed everything so you know what you are working on.
And I have positioned everything differently.
This is how it looks like:

[Image: dialogtest.png]

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtWidgets
 
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.setEnabled(True)
        Dialog.setGeometry(0, 0, 830, 700)
        Dialog.setMinimumSize(830, 400)

        self.product_id_box = QtWidgets.QComboBox(Dialog)
        self.product_id_box.setGeometry(10, 70, 100, 32)
        self.product_id_box.setFixedWidth(100)
        self.product_id_box.setEditable(True)
        self.product_id_box.setObjectName("comboBox")

        self.product_name_box = QtWidgets.QComboBox(Dialog)
        self.product_name_box.setGeometry(120, 70, 291, 32)
        self.product_name_box.setEditable(True)
        self.product_name_box.setObjectName("comboBox_3")

        self.product_id_lbl = QtWidgets.QLabel(Dialog)
        self.product_id_lbl.setGeometry(20, 50, 71, 20)
        self.product_id_lbl.setObjectName("label")
        self.product_id_lbl.setText("product_id")

        self.product_name_lbl = QtWidgets.QLabel(Dialog)
        self.product_name_lbl.setGeometry(240, 50, 101, 20)
        self.product_name_lbl.setObjectName("label_2")
        self.product_name_lbl.setText("Product_name")

        self.product_price_lbl = QtWidgets.QLabel(Dialog)
        self.product_price_lbl.setGeometry(460, 50, 60, 16)
        self.product_price_lbl.setObjectName("label_3")
        self.product_price_lbl.setText("price")

        self.product_quantity_lbl = QtWidgets.QLabel(Dialog)
        self.product_quantity_lbl.setGeometry(564, 50, 60, 16)
        self.product_quantity_lbl.setObjectName("label_4")
        self.product_quantity_lbl.setText("quantity")
   
        self.product_value_lbl = QtWidgets.QLabel(Dialog)
        self.product_value_lbl.setGeometry(710, 50, 60, 16)
        self.product_value_lbl.setObjectName("label_5")
        self.product_value_lbl.setText("value")

        self.lineEdit_price = QtWidgets.QLineEdit(Dialog)
        self.lineEdit_price.setGeometry(420, 70, 113, 32)
        self.lineEdit_price.setObjectName("lineEdit_price")
        self.lineEdit_price.setPlaceholderText("price")

        self.lineEdit_quantity = QtWidgets.QLineEdit(Dialog)
        self.lineEdit_quantity.setGeometry(540, 70, 113, 32)
        self.lineEdit_quantity.setObjectName("lineEdit_quantity")
        self.lineEdit_quantity.setPlaceholderText("quantity")

        self.product_value_box = QtWidgets.QComboBox(Dialog)
        self.product_value_box.setGeometry(660, 70, 160, 32)
        self.product_value_box.setEditable(True)
        self.product_value_box.setObjectName("comboBox_4")

        self.line = QtWidgets.QFrame(Dialog)
        self.line.setGeometry(10, 4, 810, 16)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")

        self.line_2 = QtWidgets.QFrame(Dialog)
        self.line_2.setGeometry(10, 42, 810, 16)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")

        self.line_3 = QtWidgets.QFrame(Dialog)
        self.line_3.setGeometry(10, 100, 810, 16)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")

        self.tableWidget = QtWidgets.QTableWidget(Dialog)
        self.tableWidget.setGeometry(10, 104, 810, 271)
        self.tableWidget.setRowCount(1)
        self.tableWidget.setColumnCount(5)
        self.tableWidget.setObjectName("tableWidget")

        self.editButton_3 = QtWidgets.QPushButton(Dialog)
        self.editButton_3.setGeometry(10, 14, 110, 32)
        self.editButton_3.setObjectName("pushButton_3")
        self.editButton_3.setText("Edit")

        self.deleteButton_4 = QtWidgets.QPushButton(Dialog)
        self.deleteButton_4.setGeometry(126, 14, 110, 32)
        self.deleteButton_4.setObjectName("pushButton_4")
        self.deleteButton_4.setText("Delete")

        self.clearButton = QtWidgets.QPushButton(Dialog)
        self.clearButton.setGeometry(586, 14, 113, 32)
        self.clearButton.setText("Clear")
        self.clearButton.setObjectName("pushButton")

        self.saveButton = QtWidgets.QPushButton(Dialog)
        self.saveButton.setGeometry(706, 14, 113, 32)
        self.saveButton.setObjectName("pushButton_2")
        self.saveButton.setText("Save")

        QtCore.QMetaObject.connectSlotsByName(Dialog)

        Dialog.setWindowTitle("Products")
        Dialog.statusBar().showMessage("Ready")
        
 
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QMainWindow()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())
Reply
#5
Thanks Axel_Erfurt.I am very new to PyQt.That is better than what I have got.You have really been helpful.I will update with code later. I want to create a decent application with little knowledge I have got.I am learning new features everyday.
Reply
#6
This is a version with a layout.
Then you can enlarge the window, the table increases with and the buttons remain in their position.
Except the two buttons which are arranged on the right.

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtWidgets, QtGui
  
class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setObjectName("MainWindow")
        self.setGeometry(0, 0, 830, 700)
        self.setMinimumSize(630, 400)
 
        ### horizontal box with the buttons
        self.groupBox = QtWidgets.QHBoxLayout()

        self.editButton = QtWidgets.QPushButton()
        self.editButton.setFixedWidth(90)
        self.editButton.setObjectName("editButton")
        self.editButton.setText("Edit")
 
        self.deleteButton = QtWidgets.QPushButton()
        self.deleteButton.setFixedWidth(90)
        self.deleteButton.setObjectName("deleteButton")
        self.deleteButton.setText("Delete")
 
        self.clearButton = QtWidgets.QPushButton()
        self.clearButton.setFixedWidth(90)
        self.clearButton.setText("Clear")
        self.clearButton.setObjectName("clearButton")
 
        self.saveButton = QtWidgets.QPushButton()
        self.saveButton.setFixedWidth(90)
        self.saveButton.setObjectName("saveButton")
        self.saveButton.setText("Save")

        self.groupBox.addWidget(self.editButton, 0, QtCore.Qt.AlignLeft)
        self.groupBox.addWidget(self.deleteButton, 1, QtCore.Qt.AlignLeft)
        self.groupBox.addWidget(self.clearButton, 0, QtCore.Qt.AlignRight)
        self.groupBox.addWidget(self.saveButton, 0, QtCore.Qt.AlignRight)

        ### horizontal box with the comboboxes and lineedits
        self.combogroup = QtWidgets.QHBoxLayout()
        self.product_id_box = QtWidgets.QComboBox()
        self.product_id_box.setFixedWidth(100)
        self.product_id_box.setEditable(True)
        self.product_id_box.setObjectName("product_id_box")
        self.product_id_box.lineEdit().setPlaceholderText("Product ID")
 
        self.product_name_box = QtWidgets.QComboBox()
        self.product_name_box.setFixedWidth(180)
        self.product_name_box.setEditable(True)
        self.product_name_box.setObjectName("product_name_box")
        self.product_name_box.lineEdit().setPlaceholderText("Product Name")

        self.product_value_box = QtWidgets.QComboBox()
        self.product_value_box.setFixedWidth(130)
        self.product_value_box.setEditable(True)
        self.product_value_box.setObjectName("product_value_box")
        self.product_value_box.lineEdit().setPlaceholderText("Product Value")
 
        self.lineEdit_price = QtWidgets.QLineEdit()
        self.lineEdit_price.setFixedWidth(80)
        self.lineEdit_price.setObjectName("lineEdit_price")
        self.lineEdit_price.setPlaceholderText("price")
 
        self.lineEdit_quantity = QtWidgets.QLineEdit()
        self.lineEdit_quantity.setFixedWidth(80)
        self.lineEdit_quantity.setObjectName("lineEdit_quantity")
        self.lineEdit_quantity.setPlaceholderText("quantity")

        self.combogroup.addWidget(self.product_id_box, 0, QtCore.Qt.AlignLeft)
        self.combogroup.addWidget(self.product_name_box)
        self.combogroup.addWidget(self.lineEdit_price)
        self.combogroup.addWidget(self.lineEdit_quantity)
        self.combogroup.addWidget(self.product_value_box, 1, QtCore.Qt.AlignLeft)

        ###############################################

        self.lblgroup = QtWidgets.QHBoxLayout()

        self.product_id_lbl = QtWidgets.QLabel()
        self.product_id_lbl.setFixedWidth(100)
        self.product_id_lbl.setAlignment(QtCore.Qt.AlignCenter)
        self.product_id_lbl.setObjectName("label")
        self.product_id_lbl.setText("Product ID")
 
        self.product_name_lbl = QtWidgets.QLabel()
        self.product_name_lbl.setFixedWidth(180)
        self.product_name_lbl.setAlignment(QtCore.Qt.AlignCenter)
        self.product_name_lbl.setObjectName("product_name_lbl")
        self.product_name_lbl.setText("Product Name")
 
        self.product_price_lbl = QtWidgets.QLabel()
        self.product_price_lbl.setFixedWidth(80)
        self.product_price_lbl.setAlignment(QtCore.Qt.AlignCenter)
        self.product_price_lbl.setObjectName("product_price_lbl")
        self.product_price_lbl.setText("Price")
 
        self.product_quantity_lbl = QtWidgets.QLabel()
        self.product_quantity_lbl.setFixedWidth(80)
        self.product_quantity_lbl.setAlignment(QtCore.Qt.AlignCenter)
        self.product_quantity_lbl.setObjectName("product_quantity_lbl")
        self.product_quantity_lbl.setText("Quantity")
    
        self.product_value_lbl = QtWidgets.QLabel()
        self.product_value_lbl.setFixedWidth(130)
        self.product_value_lbl.setAlignment(QtCore.Qt.AlignCenter)
        self.product_value_lbl.setObjectName("product_value_lbl")
        self.product_value_lbl.setText("Value")

        self.lblgroup.addWidget(self.product_id_lbl, 0, QtCore.Qt.AlignLeft)
        self.lblgroup.addWidget(self.product_name_lbl)
        self.lblgroup.addWidget(self.product_price_lbl)
        self.lblgroup.addWidget(self.product_quantity_lbl)
        self.lblgroup.addWidget(self.product_value_lbl, 1, QtCore.Qt.AlignLeft)
 
        ##########################################
        self.tableWidget = QtWidgets.QTableWidget()
        self.tableWidget.setRowCount(1)
        self.tableWidget.setColumnCount(5)
        self.tableWidget.setObjectName("tableWidget")
 
        #### Main Window Layout
        self.vertWidget = QtWidgets.QVBoxLayout()
        self.vertWidget.setSpacing(10)

        self.vertWidget.addLayout(self.groupBox)
        self.vertWidget.addLayout(self.lblgroup)
        self.vertWidget.addLayout(self.combogroup)

        self.vertWidget.setStretch(0, 1)
        self.vertWidget.setStretch(1, 0)

        self.vertWidget.addWidget(self.tableWidget)

        self.mainWidget = QtWidgets.QWidget()

        self.mainWidget.setLayout(self.vertWidget)

        self.setCentralWidget(self.mainWidget)
 
        QtCore.QMetaObject.connectSlotsByName(self)
 
        self.setWindowTitle("Products")
        self.statusBar().showMessage("Ready")
         
  
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())
Reply
#7
These are comboBoxes items product_id,product_name,and Product_price
1 Maclean 200
2 Laptop 30000
4 Air Fresher 50
5 Bread 200
6 Three Crown 150
7 Peak Milk 280
10 Reachable Lamp 1000
11 Torch 800
12 Radio 1000
13 Ball Point 120 respectively.
How can I get for example the comboBoxes to display if product is Maclean price should be 200 and product id 1?
This is what I have written but not working as I want it to.

        result =  session.query(Product.product_id)
        results = session.query(Product.product_name)
        lenticel= [i[0] for i in results]
        lenticels= [str(i[0]) for i in result]
        self.product_name_box.addItems(lenticel)
        self.product_id_box.addItems(lenticels) 
This is the product cart.py
from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)


#from PyQt5 import QtCore, QtWidgets
  
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.setEnabled(True)
        Dialog.setGeometry(0, 0, 830, 700)
        Dialog.setMinimumSize(830, 400)
       
        self.product_id_box = QtGui.QComboBox(Dialog)
        self.product_id_box.setGeometry(10, 70, 100, 32)
        self.product_id_box.setFixedWidth(100)
        self.product_id_box.setEditable(True)
        self.product_id_box.setObjectName("comboBox")
        
        self.product_name_box = QtGui.QComboBox(Dialog)
        self.product_name_box.setGeometry(120, 70, 291, 32)
        self.product_name_box.setEditable(True)
        self.product_name_box.setObjectName("comboBox_3")
 
        self.product_id_lbl = QtGui.QLabel(Dialog)
        self.product_id_lbl.setGeometry(20, 50, 71, 20)
        self.product_id_lbl.setObjectName("label")
        self.product_id_lbl.setText("product_id")
 
        self.product_name_lbl = QtGui.QLabel(Dialog)
        self.product_name_lbl.setGeometry(240, 50, 101, 20)
        self.product_name_lbl.setObjectName("label_2")
        self.product_name_lbl.setText("Product_name")
 
        self.product_price_lbl = QtGui.QLabel(Dialog)
        self.product_price_lbl.setGeometry(460, 50, 60, 16)
        self.product_price_lbl.setObjectName("label_3")
        self.product_price_lbl.setText("price")
 
        self.product_quantity_lbl = QtGui.QLabel(Dialog)
        self.product_quantity_lbl.setGeometry(564, 50, 60, 16)
        self.product_quantity_lbl.setObjectName("label_4")
        self.product_quantity_lbl.setText("quantity")
    
        self.product_value_lbl = QtGui.QLabel(Dialog)
        self.product_value_lbl.setGeometry(710, 50, 60, 16)
        self.product_value_lbl.setObjectName("label_5")
        self.product_value_lbl.setText("value")
 
        self.lineEdit_price = QtGui.QLineEdit(Dialog)
        self.lineEdit_price.setGeometry(420, 70, 113, 32)
        self.lineEdit_price.setObjectName("lineEdit_price")
        self.lineEdit_price.setPlaceholderText("price")
 
        self.lineEdit_quantity = QtGui.QLineEdit(Dialog)
        self.lineEdit_quantity.setGeometry(540, 70, 113, 32)
        self.lineEdit_quantity.setObjectName("lineEdit_quantity")
        self.lineEdit_quantity.setPlaceholderText("quantity")
 
        self.product_value_box = QtGui.QComboBox(Dialog)
        self.product_value_box.setGeometry(660, 70, 160, 32)
        self.product_value_box.setEditable(True)
        self.product_value_box.setObjectName("comboBox_4")
 
        self.line = QtGui.QFrame(Dialog)
        self.line.setGeometry(10, 4, 810, 16)
        self.line.setFrameShape(QtGui.QFrame.HLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName("line")
 
        self.line_2 = QtGui.QFrame(Dialog)
        self.line_2.setGeometry(10, 42, 810, 16)
        self.line_2.setFrameShape(QtGui.QFrame.HLine)
        self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
 
        self.line_3 = QtGui.QFrame(Dialog)
        self.line_3.setGeometry(10, 100, 810, 16)
        self.line_3.setFrameShape(QtGui.QFrame.HLine)
        self.line_3.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
 
        self.tableWidget = QtGui.QTableWidget(Dialog)
        self.tableWidget.setGeometry(10, 104, 810, 271)
        self.tableWidget.setRowCount(1)
        self.tableWidget.setColumnCount(5)
        self.tableWidget.setObjectName("tableWidget")
 
        self.editButton_3 = QtGui.QPushButton(Dialog)
        self.editButton_3.setGeometry(10, 14, 110, 32)
        self.editButton_3.setObjectName("pushButton_3")
        self.editButton_3.setText("Edit")
 
        self.deleteButton_4 = QtGui.QPushButton(Dialog)
        self.deleteButton_4.setGeometry(126, 14, 110, 32)
        self.deleteButton_4.setObjectName("pushButton_4")
        self.deleteButton_4.setText("Delete")
 
        self.clearButton = QtGui.QPushButton(Dialog)
        self.clearButton.setGeometry(586, 14, 113, 32)
        self.clearButton.setText("Clear")
        self.clearButton.setObjectName("pushButton")
 
        self.saveButton = QtGui.QPushButton(Dialog)
        self.saveButton.setGeometry(706, 14, 113, 32)
        self.saveButton.setObjectName("pushButton_2")
        self.saveButton.setText("Save")
 
        QtCore.QMetaObject.connectSlotsByName(Dialog)
 
        Dialog.setWindowTitle("Products")
        #Dialog.statusBar().showMessage("Ready")
         
  
if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QMainWindow()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())
    
Reply
#8
Do you use a database?
Reply
#9
(Dec-16-2018, 07:03 PM)Axel_Erfurt Wrote: Do you use a database?

Yes.

This is my product.py

import sqlalchemy
#from whooshalchemy import IndexService
from sqlalchemy import exists  
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
from sqlalchemy import create_engine, MetaData,Table
from sqlalchemy.orm import mapper,Session


    

class Product(Base):
    __tablename__   = 'products'   
   # __searchable__ = ['product_name','inventory_received','starting_inventory','inventory_on_hand','minimum_required']
    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))

    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)
metadata = MetaData()

DBsession = sqlalchemy.orm.sessionmaker(bind=engine) 
session = DBsession()
Reply
#10
You create the database yourself?
There is no database file to which you connect.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] populating dropdown from Method mikisDW 2 3,853 Apr-06-2020, 08:06 PM
Last Post: mikisDW
  Populating a Listbox from db Query DT2000 2 6,483 Feb-25-2019, 05:45 PM
Last Post: DT2000
  PyQt Selected row in Table Widget rarevesselt 3 23,693 Dec-07-2018, 07:00 PM
Last Post: rarevesselt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020