How to remove blue focus rectangle?
-
Hi and welcome to the forums
What Qt and platform is that ?
Not seen that before or at least not that big :) -
@Mufan
eitherway this already comes from a stylesheet set by you or it's the corresponding platform style.
Either way the simplest way to remove it is to using stylesheets again. -
I use stylesheets. So I've already tried:
background-color: yellow; //just to be sure it applies outline: 0px; outline: none; outline-style: none;
It doesn't work. I've found this solution related to my issue:
class Style_tweaks : public QProxyStyle { public: void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { /* do not draw focus rectangles - this permits modern styling */ if (element == QStyle::PE_FrameFocusRect) return; QProxyStyle::drawPrimitive(element, option, painter, widget); } }; qApp->setStyle(new Style_tweaks);
But I'm still thinking that there is a little bit more simple way...
-
Hi
If you create a default GUI project and add a lineedit to a form, does
it default look at like that ?
I wondering if normal style OR style sheet that does it. sorry not a mac user so dont know native look. -
@mrjj Yeah, it does. So, it's not related to my custom stylesheet.
Moreover, it is a default behavior for other applications, you know...
For example, settings for QT Creator:
The vast majority of applications shows their lineedits with this behavior. -
Theres an easy fix for that:
myLineEdit->setAttribute(Qt::WA_MacShowFocusRect,0);
will remove the mac specific focus rectangle.
-
Yeah, guys! Qt::WA_MacShowFocusRect works. It's awesome!
Thank you a lot for your time and help!P.S. Style_tweaks didn't work for me. It called only PE_FrameLineEdit and PE_PanelLineEdit, instead of PE_FrameFocusRect. Maybe I should set on some other flags and settings for that, I don't know...