Removing dotted border without setting NoFocus in Windows PyQt

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.


Set outline: 0 of the desired object. Refer following example which sets it for a QTableView.

QTableView
{
    outline: 0;
}

Works for QAbstractItemView inherited classes. (QTreeWidget, QTableWidget etc). Surprisingly this CSS property is not mentioned in the QT Documentation. See QT Style Sheet Reference Documenation.


On OSX you can do QWidget.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False). Not sure about Win or Linux. You might have to do it through stylesheets.