Nice! It works like a charm. Thanks, Russel!
On Wed, 22 Apr 2020 at 15:12, Russell Pearsall <[email protected]> wrote: > you can get the data for any role from the combobox itself > > data = combo.currentData(role=QtCore.Qt.UserRole) > > On Wednesday, April 22, 2020 at 8:39:09 AM UTC-7, Jakob Kousholt wrote: >> >> Hey Folks, I am looking to create a list within a QCombobox where the >> items have a human-readable title but is referencing an underlying unique >> id. >> >> My ComboBox will list a QStandardItemModel, which contains a >> QStandardItem per project. >> >> This is currently what I am doing: >> >> for project in self.projects: >> item = QtGui.QStandardItem() >> item.setData(project['title'], QtCore.Qt.DisplayRole) >> item.setData(project['id'], QtCore.Qt.UserRole) >> item.setCheckable(False) >> self.model.appendRow(item) >> >> I then append the QStandardItemModel to the QCombobox and it displays the >> title as expected - sweet! However, I am not sure how I will go about >> retrieving the underlying id. Currently, I use projectList.currentText() >> Which works for getting the >> current display value of the combo box, but how do I reach the underlying >> current QStandardItem and its id? >> >> Also, if there's anything I have misunderstood regarding how to work with >> these elements I'd be happy if it got pointed out. >> Thanks! >> > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/7bf94952-87b3-4651-98ed-ef779dee08ea%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/7bf94952-87b3-4651-98ed-ef779dee08ea%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAEKd6bYNin6L88-_2V%2BTZF5W11FQYe9epuOBmFtpF99jTvdM2w%40mail.gmail.com.
