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!


  • Qt Champions 2016

    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

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


  • Qt Champions 2016

    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:
    0_1516980926113_a4af050b-5fe1-48a7-a2b5-052bc6db8021-image.png
    The vast majority of applications shows their lineedits with this behavior.


  • Qt Champions 2016

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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.