Nominate our 2022 Qt Champions!

How to remove blue focus rectangle?

  • Hello! Is there any way to remove this blue focus rectangle (from QLineEdit, ex.)?
    0_1516978209492_4134589b-13a0-4987-bb15-4500829d51a9-image.png Thanks a lot!

  • Lifetime Qt Champion

    Hi and welcome to the forums

    What Qt and platform is that ?
    Not seen that before or at least not that big :)

  • Hi mrjj! :)
    Qt Creator 4.4.1
    Based on Qt 5.9.2 (Clang 7.0 (Apple), 64 bit)
    macOS Sierra 10.12.6

  • Moderators

    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
            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)
                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...

  • Lifetime Qt Champion

    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.

  • Lifetime Qt Champion

    Ok so it is the platform QStyle.
    So the Style_tweaks is not a bad way of you want it for all lineedits you have as
    its most effective for a global override.

  • Moderators

    Theres an easy fix for that:


    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...

Log in to reply