PDA

View Full Version : How to control the color of the focus rectangle



Berryblue031
18th May 2011, 14:08
The standard focus rectangle draws as either white or black depending on the background of the widget (from what I can tell anyways)

In my application I have styled QPushButton via stylesheets to have a gradient background that is very light and requires a black focus rectangle, but Qt is drawing a white focus rectangle! If I change the background color to be solid and the darkest color of my gradient I get the black focus rectangle so I can only assume that gradient background is confusing the painter.

How can I force it to draw the focus rectangle in black?

Note that setting the style QPushButton:focus gives a completely different effect it changes the overall look of the button when it has focus and not the focus rectangle itself.

Berryblue031
23rd May 2011, 14:19
As a follow up, as of 4.7.2 it is not possible to style the focus rectangle yourself, so it should be able to calculate it's color properly when the widget's background is a gradient.

I reported it as a bug and it can be followed here
http://bugreports.qt.nokia.com/browse/QTBUG-19406

curonia
21st June 2012, 13:55
Hi,

I know it's an old thread, but in case someone wonders in looking for info - you can change focus rectangle using stylesheets. Use option outline.

if you want your focus rectangle for QPushButton to be black, use style

QPushButton { outline: 1px solid #000 }

oh, btw ... i'm using this in 4.8.2