Au lieu d'utiliser .addItem("Item Name", "My Data")
pour alimenter le QComboBox
Comment obtenir QComboBox données d'article
Je crée son article premier:
item = QtGui.QStandardItem("Item Name")
Je mis les données de l'article:
item.setData("My data")
Question. Comment obtenir les données stockées dans l'élément de Combo à l'intérieur de la méthode currentIndexChanged()
qui obtient l'indice de l'élément ComboBox cliquée comme argument:
import sys
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
class MyCombo(QtGui.QWidget):
def __init__(self, *args):
QtGui.QWidget.__init__(self, *args)
vLayout=QtGui.QVBoxLayout(self)
self.setLayout(vLayout)
self.combo=QtGui.QComboBox(self)
self.combo.currentIndexChanged.connect(self.currentIndexChanged)
comboModel=self.combo.model()
for i in range(3):
item = QtGui.QStandardItem(str(i))
item.setData('MY DATA' + str(i))
comboModel.appendRow(item)
vLayout.addWidget(self.combo)
def currentIndexChanged(self, index):
print index
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
w = MyCombo()
w.show()
sys.exit(app.exec_())
question redondante, vous avez obtenu la réponse il y a déjà quelques jours ici: http://stackoverflow.com/questions/31998023/qcombobox-and -app-setstylecleanlooks –