View Full Version : How to change LineEdits and ComboBx focus style

26th February 2015, 09:06

I'm making a gui app with Qt 4.8.5. I have a basic wizard with 3 wizardpages. On the fisrt one I have a combobox (mycb) and two lineedits (le1 and le2).

The thing is that when the have the focus they have a thin light blue border which I would like to change and make it bigger or to have another color so the user can see which element has the focus clearly.

I've tried to do it first with the combobox, implementing a BaseComboBox (class BaseComboBox : public QComboBox) class with that:

void BaseComboBox::focusInEvent(QFocusEvent *e)
if (e->reason() == Qt::TabFocusReason)

and then in the wizard page constructor:

connect(mycb,SIGNAL(changeStyle()),this, SLOT(changeStyleSLOT())); // BaseComboBox mycb;

and the slot:

void WPConfigs12::changeStyleSLOT()
mycb->setStyleSheet("BaseComboBox:focus { border: 5px solid red;");

But it doesn't change. It just works as always with the thin blue default border. Any idea for that?

Thank you so much!

26th February 2015, 13:22
You don't have to apply the stylesheet when the focus is happening, you can just set it at the start of the program for the form

myComboBoxContainingForm->setStyleSheet(QComboBox:focus{ border: 5px solid red; });
now all QComboBoxes will get a red 5px border when they are focused

26th February 2015, 16:50
You are right StrikeByte... I just made a mess with the stylesheets so once I fixed it what you said worked fine. Thank you so much! So simple and I wasn't able to see it hehe