Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to remove blue focus rectangle?

    General and Desktop
    4
    10
    4663
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mufan
      Mufan last edited by

      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!

      raven-worx 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by mrjj

        Hi and welcome to the forums

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

        1 Reply Last reply Reply Quote 0
        • Mufan
          Mufan last edited by

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

          1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @Mufan last edited by

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

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 1
            • Mufan
              Mufan last edited by

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

              1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion last edited by

                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.

                Mufan 1 Reply Last reply Reply Quote 0
                • Mufan
                  Mufan @mrjj last edited by

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

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @Mufan last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • J.Hilk
                      J.Hilk Moderators last edited by

                      Theres an easy fix for that:

                      myLineEdit->setAttribute(Qt::WA_MacShowFocusRect,0);
                      

                      will remove the mac specific focus rectangle.

                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

                      Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply Reply Quote 7
                      • Mufan
                        Mufan last edited by

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

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post