Python Forum
[PyQt] [Solved]Add a SpinBox to MsgBox or Carry Variable Over?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] [Solved]Add a SpinBox to MsgBox or Carry Variable Over?
#7
So here's what I'm trying to do.

I have two scripts: AdminMenu.py and the CheckoutPoup.py.

When the user selects an entire row(as show in the attached screenshot) the selected item's Name, and ID are carried over from the AdminMenu.py to the CheckoutPopup.py. That way I can use the item's ID in my SQL UPDATE statement and display the item's Name on the Checkout popup window so the user knows what Item they are checking out (The message/label will display something like: "You are taking: 4 Test Item").

So how do I carry over the selected item's Name and ID to the Checkout.py?
(Since I plan on doing it this way I no longer have to carry over the SpinBox value since everything will be done in the CheckoutPopup.py. But I still need to figure out how to carry the Name & ID over)

AdminMenu.py Inventory Display code snippet:
#----------------------------------------------------------------------------------------------------
#                                       Inventory Display
#----------------------------------------------------------------------------------------------------

        #Connect to Database
        self.db = QSqlDatabase.addDatabase('QSQLITE')
        self.db.setDatabaseName('inventory.db')
        self.model = QSqlTableModel()
        self.delrow = -1
        self.initializeModel()

        self.sbar = self.statusBar()

        self.InventoryDisplay = QTableView()
        self.InventoryDisplay.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.InventoryDisplay.setModel(self.model)
        self.InventoryDisplay.clicked.connect(self.findrow)
        self.InventoryDisplay.selectionModel().selectionChanged.connect(self.getCellText)

        self.gridLayout.addWidget(self.InventoryDisplay, 4, 1, 1, 2)
        self.setCentralWidget(self.centralwidget)

        #Call the function to calculate the SellPrice
        self.calculate_sellprice()

    def initializeModel(self):
       self.model.setTable('items')
       self.model.setEditStrategy(QSqlTableModel.OnFieldChange)
       self.model.select()

        #------------------------------------------
                        #Search/Filter
        #------------------------------------------
        #Allows the user to search for items
       self.SearchFilter.clear()
       for i in range(self.model.columnCount()):
            self.SearchFilter.addItem(self.model.headerData(i, QtCore.Qt.Horizontal))
       self.SearchFilter.setCurrentIndex(1)
 
       self.SearchBar.textChanged.connect(self.filter_table)
 
    def filter_table(self, text):
        userQuery = " {} LIKE '%{}%'".format(self.SearchFilter.currentText(), text.lower()) if text else text
        self.model.setFilter(userQuery)
        self.model.select()
        #------------------------------------------
        
#----------------------------------
#       Update Inventory
#---------------------------------- 
    def findrow(self, i):
        self.delrow = i.row()
 
    def getCellText(self):
        if self.InventoryDisplay.selectedIndexes():
            item = self.InventoryDisplay.selectedIndexes()[0]
            row = self.selectedRow()
            column = self.selectedColumn()
            if not item == None:
                name = item.data()
                self.sbar.showMessage(str(name))
 
    def selectedRow(self):
        if self.InventoryDisplay.selectionModel().hasSelection():
            row =  self.InventoryDisplay.selectionModel().selectedIndexes()[0].row()
            return int(row)
 
    def selectedColumn(self):
        column =  self.InventoryDisplay.selectionModel().selectedIndexes()[0].column()
        return int(column)
#----------------------------------
    #------------------------------------------------------------------------
    #When Price is Updated Automatically Update SellPrice When Refresh is Hit
    #------------------------------------------------------------------------
    def calculate_sellprice(self):
        for row in range(self.InventoryDisplay.model().rowCount() - 1):
                sell_price = str(self.InventoryDisplay.model().index(row, 3).data())
                if sell_price:
                        sell_price = f'{float(sell_price.replace(",", ".")) * Markup:.2f}'
                        self.InventoryDisplay.model().setData(self.InventoryDisplay.model().index(row, 4), sell_price)

        #----------------------------------
        #Make Specific Columns Un-Editable/ReadOnly
        #----------------------------------
        class ReadOnlyDelegate(QStyledItemDelegate):
                def createEditor(self, parent, option, index):
                        print('This column is Read-Only')
                        return 

        delegate = ReadOnlyDelegate(self)
        self.InventoryDisplay.setItemDelegateForColumn(0, delegate) #ID
        self.InventoryDisplay.setItemDelegateForColumn(2, delegate) #Quantity
        self.InventoryDisplay.setItemDelegateForColumn(4, delegate) #SellPrice
        self.InventoryDisplay.setItemDelegateForColumn(10, delegate) #Date Added
        #----------------------------------
#----------------------------------------------------------------------------------------------------

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
RE: Add a SpinBox to MsgBox or Carry Variable Over? - by Extra - Jun-05-2022, 09:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Validating and modifying a Spinbox pfdjhfuys 2 1,263 May-21-2023, 12:17 PM
Last Post: pfdjhfuys
  [PyQt] [Solved]How to Run GUI MsgBox From Terminal Properly Extra 4 1,758 Oct-03-2022, 11:01 PM
Last Post: Extra
  [PyQt] [Solved]Help getting variable from Function in PyQt Extra 6 1,530 Jul-06-2022, 10:19 PM
Last Post: Extra
  [Tkinter] how to celect com port from spinbox and make connect button 00alkskodi00 0 2,466 Apr-20-2020, 02:26 PM
Last Post: 00alkskodi00

Forum Jump:

User Panel Messages

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