Search code examples
qtfocusborderqlineeditqtstylesheets

How to prevent the default blue border being drawn on QLineEdit focus


I am trying to achieve a borderless QLineEdit through CSS. It works fine when the QLineEdit is not in focus but when in focus the default blue border always comes up. The simple CSS I am using:

QLineEdit, QLineEdit:focus { border: none; }

I have tried with different background color through CSS for focus and not-in-focus, it works but I am unable to remove the blue border while in focus. Just to inform, I am working on a Mac.


Solution

  • You might get rid of the focus border by setting:

    QLineEdit.setAttribute(Qt::WA_MacShowFocusRect, 0)
    

    Read the documentation, there are plenty of other Mac specific settings WidgetAttribute-enum

    There is rather a similar question too Refer this question