There are a few questions on SO about this, all of which seem to say that the only way to remove the dotted border is to set the focusPolicy on widget/item in question to NoFocu
Most styles delegate the drawing of the focus indicator to the QStyle::drawPrimitive
function with PE_FrameFocusRect
as the element to be drawn.
So you should be able to disable that globally with the following style class installed on the application instance:
class NoFocusProxyStyle : public QProxyStyle {
public:
NoFocusProxyStyle(QStyle *baseStyle = 0) : QProxyStyle(baseStyle) {}
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const {
if(element == QStyle::PE_FrameFocusRect) {
return;
}
QProxyStyle::drawPrimitive(element, option, painter, widget);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyle(new NoFocusProxyStyle);
...
PS: It doesn't work with QGtkStyle
for some widgets (buttons, combobox), so it might not work for Windows or Mac either.