python - PyQt: Get the highlighted index from QComboBox -


i want obtain index of highlighted item in qcombobox. how can access variable?

the sample code have:

    ...     self.combobox = qtwidgets.qcombobox()     self.combobox.additems(['a', 'b', 'c'])     self.combobox.highlighted.connect(self.return_higlighted_index)     ...  def return_highlighted_index(self):     print('the current highlighted index is: ', '?') 

instead of

self.combobox.highlighted.connect(self.return_higlighted_index) 

try (not tested)

self.combobox.activated[str].connect(self.return_higlighted_index)  def return_highlighted_index(self, combobox_entry):     idx = self.combobox.findtext(combobox_enty)     print('the current highlighted index is: {}'.format(idx)) 

so connect method return_highlighted_index combobox whenever changed passes current highlighted string method return_highlighted_index combobox_entry return_highlighted_index() should able obtain index.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -