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

2

10

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.

Manyplies answered 11/11, 2012 at 1:30 Comment(1)
Your style sheet works for me in Windows. So does Nikos's solution. Maybe create a small compilable example on your Mac, and if the problem persists, file a bug report.Camaraderie
M
14

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

Merralee answered 12/11, 2012 at 3:35 Comment(1)
Thanks. But in QT5.4, it should be Qt::WA_MacShowFocusRect instead of Qt.WA_MacShowFocusRectCns
A
0

Maybe also like this way:

ui->treeView->setAttribute(Qt::WA_MacShowFocusRect, 0);

Reference: http://doc.qt.digia.com/4.6/demos-interview-main-cpp.html

Anemometer answered 10/12, 2014 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.