Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to remove blue focus rectangle?
Forum Updated to NodeBB v4.3 + New Features

How to remove blue focus rectangle?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 5.8k Views 2 Watching
  • 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.
  • MufanM Offline
    MufanM Offline
    Mufan
    wrote on last edited by
    #1

    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-worxR 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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
      0
      • MufanM Offline
        MufanM Offline
        Mufan
        wrote on last edited by
        #3

        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
        0
        • MufanM Mufan

          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-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @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
          1
          • MufanM Offline
            MufanM Offline
            Mufan
            wrote on last edited by
            #5

            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
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              MufanM 1 Reply Last reply
              0
              • mrjjM mrjj

                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.

                MufanM Offline
                MufanM Offline
                Mufan
                wrote on last edited by
                #7

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

                mrjjM 1 Reply Last reply
                0
                • MufanM Mufan

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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
                  0
                  • J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    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


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

                    1 Reply Last reply
                    7
                    • MufanM Offline
                      MufanM Offline
                      Mufan
                      wrote on last edited by
                      #10

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved