Qt World Summit: Submit your Presentation

QComboBox retains mouse hover highlight if you close popup

  • Hello,

    I am having some issues styling my QComboBoxes. I want to have them highlight when mouse over, but it seems they retain the highlight if I click on them and then close the pop-up (either by clicking outside or by selecting something, does not matter). I am using Qt 5.13.1 and I see this issue on macOS and Linux. Haven't tested on others but I guess it would be the same.

    My style is this simple, maybe I am missing something:

      background-color: rgba(0, 0, 0, 0.2);

  • Lifetime Qt Champion

    So on mac/linux its not doing like this ? (win 10)
    alt text

  • My stylesheet change make it a light gray color when the mouse hovers on it. When the mouse moves to the outside of it it reverts back to original color. After you click it and then close the popup (either select something or click outside) the combobox stays light gray instead of reverting back.

  • Ok, I managed to work around this issue, will write it here in case anybody else has this problem. I quit trying to use qss and did it in the code. Subclassed the QComboBox and added the hover events:

    bool TrackableComboBox::event(QEvent *event)
        switch (event->type())
            case QEvent::Enter:
                this->setStyleSheet("background-color: rgba(0, 0, 0, 0.2);");
            case QEvent::Leave:
            case QEvent::MouseButtonPress:
                this->setStyleSheet("background-color: -1;");
        return QWidget::event(event);

    The secret here is to add Leave and MouseButtonPress reset the color, otherwise you will have the same issue.

Log in to reply