I have a PyQt GUI using Python 2.7 and QT 4.7 that opens a dialog called by a pushbutton. I can pass values between the dialog and the main GUI just fine for the most part, until it comes to a QSpinBox in the dialog box.
The class that defines the dialog is like so:
class BuyDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
global ci, space, cash, current, price, qtyToBuy
self.ui = Ui_buyDialog() # Set up the user interface from Designer.
self.ui.setupUi(self)
for i in range(0, len(ci)):
item = str(ci[i][0])
price = str(ci[i][1])
self.ui.itemsComboBox.addItem(item)
price = str(self.getPrice())
gPrice = "$" + price
print gPrice
self.ui.priceFieldLabel.setText(gPrice)
self.ui.itemsComboBox.currentIndexChanged['QString'].connect(self.updateItems)
self.ui.availableSpaceFieldLabel.setText(space)
canBuy = str(funcs.youCanAfford(cash, price))
self.ui.canAffordFieldLabel.setText(canBuy)
qtyToBuy = self.ui.buySpinBox.value()
The code that handles the dialog itself is
def buyDialog(self):
global current, price, qtyToBuy
dialog = BuyDialog()
result = dialog.exec_()
if result:
dialogResult = (current, price, qtyToBuy)
print dialogResult #debug
return dialogResult
current
comes from a combo box in the dialog, and price
comes from a list lookup against current
. I know the dialog updates correctly, as the values returned for current
and price
are correct. However, qtyToBuy
always returns 0. The only way I've gotten it to return anything different is by calling setValue()
on it when it's initiated. Everywhere I've looked, I get the impression I'm the only person that's had this problem, as I can find nothing else regarding this issue. Does anyone have any idea what the problem is?