Search code examples
c++qtpyqt4qcombobox

Hide Icon from the label of QComboBox


I am trying to implement a QComboBox, which holds QIcon and QString, like this:

QComboBox.addItem(icon, label);

I want the icons to be visible in the drop-down list, but not in the toolbar. Only the string should be visible after item selection.

Is there an easy way to do this?


Solution

  • The best way is to set a delegate and to draw the items yourself. Then you can choose when or not to draw the icon ( decorationRole ), you can choose not to draw the icon for the index which is the current index. I could find a quick example on how to use a delegate on combobox: http://programmingexamples.net/wiki/Qt/Delegates/ComboBoxDelegate

    But I am afraid it is not the most easist of the ways. Good luck!