Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved QComboBox highlighting

    General and Desktop
    2
    5
    1023
    Loading More Posts
    • 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.
    • BjornW
      BjornW last edited by

      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 Reply Quote 0
      • V
        VRonin last edited by

        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 Reply Quote 3
        • BjornW
          BjornW last edited by

          Wouldn't that disable highlighting for the text also?

          1 Reply Last reply Reply Quote 0
          • V
            VRonin last edited by

            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 Reply Quote 3
            • BjornW
              BjornW last edited by

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

              This seemes to work!

              1 Reply Last reply Reply Quote 3
              • First post
                Last post