I have a QPixmap within a QLabel that is changed based on a QComboBox selection. For example, the combobox may have a selection of fruits (e.g., 'apple', 'orange', 'banana'). If I choose 'apple' an image of an apple is displayed in the QLabel. I further want the image of the apple to change to a "special" image of an apple depending on whether a QRadioButton is toggled. Once I de-toggle the radio button the image should revert to the standard apple image. Currently I have it partially functional: if the radio button is toggled 'on' prior to selecting the combobox option, the image is displayed as desired; if, however, I toggle the radio button 'on' after selecting the combobox option only the standard image is displayed. Similarly, if I have the special image displayed and de-toggle the radio button, the image does not revert to the standard image.
I assume this has something to do with the "toggled()" method, but not sure how to implement it.
self.fruit_list = ['apple', 'orange', 'banana']
self.fruit_combo = QtGui.QComboBox()
self.fruit_combo.addItems(self.fruit_list)
self.btn = QtGui.QRadioButton("btn")
self.fruit_image = QtGui.QLabel(self)
self.grid.addWidget(self.fruit_image, 1, 1)
self.fruit_combo.currentIndexChanged[str].connect(lambda:
self.image_update(self.fruit_combo, self.fruit_image, self.btn)
def image_update(self, qcombobox, qlabel, btn):
image_path ="c :/images"
current_item = str(qcombobox.currentText())
if btn.isChecked():
current_image = '%s/%s_special.jpg' %(image_path, current_item)
else:
current_image = '%s/%s.jpg' %(image_path, current_item)
qlabel.setPixmap(QtGui.QPixmap(current_image))
Thanks