Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox highlighting
Forum Updated to NodeBB v4.3 + New Features

QComboBox highlighting

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BjornWB Offline
    BjornWB Offline
    BjornW
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • BjornWB Offline
        BjornWB Offline
        BjornW
        wrote on last edited by
        #3

        Wouldn't that disable highlighting for the text also?

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

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

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3
          • BjornWB Offline
            BjornWB Offline
            BjornW
            wrote on last edited by
            #5

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

            This seemes to work!

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved