View Full Version : How to highlight a QWidget

15th May 2014, 00:14
Hello everyone! Here is my question:

I've derived the QToolButton so that buttons in QToolBar can be accessed by tabbing, but when it gains focus it is not highlighted like when i hover with the cursor over it. I've overriden the focusInEvent function, but when it comes to actually highlighting the button I don't know what property/attribute to set or what method to call.

Here is what it looks like when I hover with the cursor over the button:
How can I achieve this by replacing the line marked?

Here is what is currently happening:

void focusInEvent(QFocusEvent* e){
if(e->gotFocus() && e->reason() == Qt::TabFocusReason){
setGraphicsEffect(new QGraphicsColorizeEffect()); //line to be replaced

Thank you for your help! :)

21st May 2014, 09:08
Try style sheet for the widget focus, see below style sheet example for QWidget focus...

QWidget:focus {border: 3px solid green;}