QComboBox: Focus Qt Style Sheet

I have an editable combo box in an input form that needs to change its background when it receives focus. The following code works fine for QLineEdit, but does not affect QComboBox.

QLineEdit, QComboBox { background-color: green; }
QLineEdit:focus, QComboBox:focus { background-color: red; }

      

Is it possible that the QComboBox behaves as expected, like QLineEdit , using only Qt style sheets ?

+3


source to share


1 answer


You may need to do this by subclassing QLineEdit and setting it to the combo box (s QComboBox::setLineEdit()

). Then override the focusIn () and focusOut () QLineEdit functions and set the stylesheet with the appropriate background color in those functions.



Another way is to set an event handler on the combo box (and / or its associated QLineEdit) and turn on / off focus on focus and change the stylesheet.

0


source







All Articles