Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QComboBox highlighting



  • Hi!

    I'm having problems using QComboBox (Qt.4.6).

    Each item has a (colored) icon and text. This works fine. However, when I highlight an item by moving the mouse over it, highlight color gets applied also to the icon in the list. When an icon is yellow it gets highlighted via a blue transparent layer to green which is confusing because we also have green icons in the list. I would like to disable higlighting of the icon portion of the dropdown. Is that possible?

    //Björn



  • Yes but it might need a bit of messing around.
    That's just a listview you can access via comboBox->view() you have to set a delegate to it to get what you want.

    On top of my head I'd subclass QStyledItemDelegate, reimplement paint copying it from the original and just add:

    opt.text.clear();
    opt.state &= ~QStyle::State_Selected;
     style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
    

    at the end. This might mess up if you also have checkboxes but I assume it's not the case



  • Wouldn't that disable highlighting for the text also?



  • yeah, fair point, you'll probably need to set the background brush to Qt::transparent as well



  • m_icon.addPixmap(greenPixmap, QIcon::Normal);
    m_icon.addPixmap(greenPixmap, QIcon::Selected);

    This seemes to work!


Log in to reply