So I have figured out how to dynamically generate controls how I wanted in QDialog for question i asked here but now I am not able to set the value on QSpinBox from the dictionary below
books = {
'Contact':['Carl Sagan', 2],
'End of Faith':['Sam Harris', 7],
'on Mars':['Patrick Moore', 1],
}
def buildUi(self):
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setSpacing(10)
for index, (key, values) in enumerate(self._data.iteritems()):
getLbl = QtGui.QLabel("Get", self)
label = QtGui.QLabel(key, self)
chkBox = QtGui.QCheckBox(self._data[key][0], self)
chkBox.setToolTip("Click here to get the book")
version = QtGui.QSpinBox(self._data[key][-1], self)
self.gridLayout.addWidget(getLbl, index, 0)
self.gridLayout.addWidget(label, index, 1)
self.gridLayout.addWidget(chkBox, index, 2)
self.gridLayout.addWidget(version, index, 3)
self.layout = QtGui.QVBoxLayout()
self.okBtn = QtGui.QPushButton("OK")
self.layout.addLayout(self.gridLayout)
self.horLayout = QtGui.QHBoxLayout()
self.horLayout.addStretch(1)
self.horLayout.addWidget(self.okBtn)
self.layout.addLayout(self.horLayout)
self.setLayout(self.layout)
Here is the error message I am getting:
Traceback (most recent call last):
File "~/Development/custom/MessageBox.py", line 58, in _launchMessageBox
dlg = MessageBox(self._data)
File "~/Development/custom/MessageBox.py", line 10, in __init__
self.buildUi()
File "~/Development/custom/MessageBox.py", line 21, in buildUi
version = QtGui.QSpinBox(self._data[key][-1], self)
TypeError: QSpinBox(QWidget parent=None): argument 1 has unexpected type 'int'
[Finished in 4.5s]
Also how do I set the limit in QSPinBox ?
According to
QSpinBox.__init__
documentation, it does take onlyparent
parameter.Replace following line:
with:
If you want the initial value to be set, use
setValue
: