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. Grey Border On Tab
QtWS25 Last Chance

Grey Border On Tab

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 934 Views
  • 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.
  • S Offline
    S Offline
    sofneo
    wrote on last edited by
    #1

    Does anyone know how to get rid of this zebra border when I click tab? Appreciated.
    https://gyazo.com/0c998844de3cd409c329372a8117b628

    JonBJ 1 Reply Last reply
    0
    • S sofneo

      Does anyone know how to get rid of this zebra border when I click tab? Appreciated.
      https://gyazo.com/0c998844de3cd409c329372a8117b628

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @sofneo
      Don't know the platform, but that looks like the visual focus rectangle?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sofneo
        wrote on last edited by
        #3

        By any chance do you know how to remove it?

        mrjjM JonBJ 2 Replies Last reply
        0
        • S sofneo

          By any chance do you know how to remove it?

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

          @sofneo
          What widget is it ?
          Looks like a button to me and a focus rect or active rect on some platform i dont know.

          1 Reply Last reply
          0
          • S sofneo

            By any chance do you know how to remove it?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @sofneo
            If it's that, I'm thinking https://doc.qt.io/qt-5/stylesheet-reference.html#list-of-pseudo-states,

            :focus The item has input focus.

            Have a read through https://stackoverflow.com/questions/17280056/qt-css-decoration-on-focus. If the last one there is correct, maybe just

            QPushButton:focus {
               border: none;
               outline: none;
            }
            

            will do it?

            1 Reply Last reply
            3
            • S Offline
              S Offline
              sofneo
              wrote on last edited by sofneo
              #6

              Yes, it works! I've been stuck on this for so long and I'm so happy. I'm currently using:
              'ui.exit_long_button->setStyleSheet("QPushButton:focus{border: none;outline: none;}");'
              however is there a more logistic way of doing this because this overwrites all of the current settings? I just want it to change the QPushButton:focus rather than overwrite all of the properties.

              JonBJ 1 Reply Last reply
              0
              • S sofneo

                Yes, it works! I've been stuck on this for so long and I'm so happy. I'm currently using:
                'ui.exit_long_button->setStyleSheet("QPushButton:focus{border: none;outline: none;}");'
                however is there a more logistic way of doing this because this overwrites all of the current settings? I just want it to change the QPushButton:focus rather than overwrite all of the properties.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #7

                @sofneo

                I just want it to change the QPushButton:focus rather than overwrite all of the properties.

                • You can try instead doing the focus via QStyle code. Don't know what you'd need to do for that, maybe that link helps you.

                • You do not have to set stylesheet on a QWidget explicitly. You can have a big stylesheet on the application as a whole, and set that setStyleSheet(const QString &sheet). If your rule is QPsshButton ... it would apply to all push buttons, if you only want it on specific you could e.g. give it an objectName and use #theObjectName ... rule selector to address just that button.

                • When wanting to add stylesheet to an element which may already have its own stylesheet without destroying whatever might or might not be there, you should do:

                QString ss = btn->styleSheet();
                ss += " QPushButton:focus{border: none;outline: none;}";
                btn->setStyleSheet(ss);
                
                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sofneo
                  wrote on last edited by
                  #8

                  It doesn't seem to work. This is the code that I'm using:

                      QString new_stylesheet = ui.exit_long_button->styleSheet();
                      new_stylesheet += "QPushButton:focus{border: none;outline: none;}";
                      ui.exit_long_button->setStyleSheet(new_stylesheet);
                  

                  Button before: https://gyazo.com/a5215294117b7464cf77e774acb30a67
                  Button after: https://gyazo.com/ee2154ec99096cb5754c2930f29d8b2c

                  JonBJ 1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    Bonnie
                    wrote on last edited by Bonnie
                    #9

                    Do you need keyboard focus or not?
                    If you don't need the button to get keyboard focus, you can simply use setFocusPolicy(Qt::NoFocus) (also can be set in designer).
                    Then it will never be focused, hence never has focus frame.

                    S 1 Reply Last reply
                    2
                    • S sofneo

                      It doesn't seem to work. This is the code that I'm using:

                          QString new_stylesheet = ui.exit_long_button->styleSheet();
                          new_stylesheet += "QPushButton:focus{border: none;outline: none;}";
                          ui.exit_long_button->setStyleSheet(new_stylesheet);
                      

                      Button before: https://gyazo.com/a5215294117b7464cf77e774acb30a67
                      Button after: https://gyazo.com/ee2154ec99096cb5754c2930f29d8b2c

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by JonB
                      #10

                      @sofneo

                      It doesn't seem to work.

                      You are the one who said

                      Yes, it works! I've been stuck on this for so long and I'm so happy. I'm currently using:

                      'ui.exit_long_button->setStyleSheet("QPushButton:focus{border: none;outline: none;}");'

                      If it works for that it should work for the new_stylesheet way. Unless, at a guess, you have something there which is not already terminated by a ; so you end up with illegal

                      something: somevalue  QPushButton:focus{border: none;outline: none;}
                      

                      Don't do that! Always leave your stylesheet rules properly terminated!

                      Print out new_stylesheet and look at it. If you need to code for preceeding something do so (e.g. add a terminating ;), or put the new stuff at the beginning instead:

                      new_stylesheet = "QPushButton:focus{border: none;outline: none;} " + new_stylesheet;
                      

                      If you can afford to solve your problem @Bonnie 's way that's fine. You should in any case be familiar with how you can alter existing stylesheets.

                      1 Reply Last reply
                      2
                      • B Bonnie

                        Do you need keyboard focus or not?
                        If you don't need the button to get keyboard focus, you can simply use setFocusPolicy(Qt::NoFocus) (also can be set in designer).
                        Then it will never be focused, hence never has focus frame.

                        S Offline
                        S Offline
                        sofneo
                        wrote on last edited by
                        #11

                        @Bonnie Thanks - worked a charm!

                        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