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. Focus ring around tree/table views?
Forum Updated to NodeBB v4.3 + New Features

Focus ring around tree/table views?

Scheduled Pinned Locked Moved Unsolved General and Desktop
33 Posts 5 Posters 10.7k Views 3 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by
    #9

    because it looks great, makes it clear where the focus is, and i want the EXACT SAME look on both mac and windows. also, my previous iteration of my app did it and the last thing i want to do is REMOVE FEATURES with an app rewrite, because that's the most horrible thing any dev can do to it's installed base

    1 Reply Last reply
    0
    • D davecotter

      @j-hilk said in Focus ring around tree/table views?:

      QTreeView:focus {
      border: 1px solid #6a6ea9;
      }

      i took your suggestion but the "ring" is practically invisible. As you can see i'm setting it to 3 pixels but that doesn't change it's width for some reason?:

      0_1565288173141_Screen Shot 2019-08-08 at 11.15.07 AM.png

      Search bar does it correctly:
      0_1565288154232_Screen Shot 2019-08-08 at 11.14.45 AM.png

      No ring around treeview:
      0_1565288166232_Screen Shot 2019-08-08 at 11.14.51 AM.png

      No ring around table view:
      0_1565288219164_Screen Shot 2019-08-08 at 11.14.56 AM.png

      should i be using QFocusFrame ?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #10

      @davecotter
      you clearly did not write what I did, right? only 1 : not ::focus

      #include <QApplication>
      #include <QWidget>
      #include <QTableWidget>
      #include <QTreeWidget>
      #include <QHBoxLayout>
      
      int main(int argc, char *argv[])
      {
      
          QApplication a(argc, argv);
      
          QWidget w;
          QHBoxLayout *layout = new QHBoxLayout(&w);
      
          QTreeWidget tr;
          tr.setStyleSheet("QTreeWidget:focus{border: 4px solid red;}");
      
          QTableWidget ta;
          ta.setStyleSheet("QTableWidget:focus{border: 4px solid red;}");
      
          layout->addWidget(&tr);
          layout->addWidget(&ta);
      
          w.resize(400,400);
          w.show();
      
          return  a.exec();
      }
      

      0_1565290530966_d8ac3aa7-9ac6-471b-bbf9-5551d3b45cf4-image.png

      0_1565290545916_6d8ff5a3-e7de-429b-adbf-e69ce9139a8a-image.png


      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.

      D 1 Reply Last reply
      2
      • M Offline
        M Offline
        mpergand
        wrote on last edited by
        #11

        @davecotter said in Focus ring around tree/table views?:

        because it looks great, makes it clear where the focus is

        It's your own opinion ...
        Regular users on other systems could find this extra border annoying, or don't care at all.
        Stay the standard way and every users of your apps will be happy ...

        1 Reply Last reply
        0
        • D Offline
          D Offline
          davecotter
          wrote on last edited by davecotter
          #12

          @mpergand I appreciate your taking the time to answer, and in trying to guide me, however i'm not here for a critique of my UX, i'm here for technical details on how to accomplish a goal. My users have been seeing a focus ring for over ten years, and zero have told me they don't like it. I'm not going to change the UX, because people come to rely on visual indicators, and when you take them away is when users get upset.

          In any case it seems that i must come up with a different approach. May i ask how the text edit focus ring is accomplished? Or is there sample code for QFocusFrame ? the doc is cryptic and my first attempt lead to nothing.

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @davecotter
            you clearly did not write what I did, right? only 1 : not ::focus

            #include <QApplication>
            #include <QWidget>
            #include <QTableWidget>
            #include <QTreeWidget>
            #include <QHBoxLayout>
            
            int main(int argc, char *argv[])
            {
            
                QApplication a(argc, argv);
            
                QWidget w;
                QHBoxLayout *layout = new QHBoxLayout(&w);
            
                QTreeWidget tr;
                tr.setStyleSheet("QTreeWidget:focus{border: 4px solid red;}");
            
                QTableWidget ta;
                ta.setStyleSheet("QTableWidget:focus{border: 4px solid red;}");
            
                layout->addWidget(&tr);
                layout->addWidget(&ta);
            
                w.resize(400,400);
                w.show();
            
                return  a.exec();
            }
            

            0_1565290530966_d8ac3aa7-9ac6-471b-bbf9-5551d3b45cf4-image.png

            0_1565290545916_6d8ff5a3-e7de-429b-adbf-e69ce9139a8a-image.png

            D Offline
            D Offline
            davecotter
            wrote on last edited by
            #13

            @j-hilk well, it turns out not to have mattered. With 1 OR 2 colons, you get the same result, one pixel wide border, not the number of pixels you specify. Even your example, specifying 4px, it only shows a 1px border. but thanks for the test!

            J.HilkJ 1 Reply Last reply
            0
            • D davecotter

              @j-hilk well, it turns out not to have mattered. With 1 OR 2 colons, you get the same result, one pixel wide border, not the number of pixels you specify. Even your example, specifying 4px, it only shows a 1px border. but thanks for the test!

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #14

              @davecotter you're welcome 😉

              strange I can confirm that, but the pixel size used to make a difference 🤔


              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
              0
              • D Offline
                D Offline
                davecotter
                wrote on last edited by
                #15

                @mpergand said in Focus ring around tree/table views?:

                treeView->setAttribute(Qt::WA_MacShowFocusRect);

                note i tried this on the mac just to SEE it, and got exactly nothing. is there no way to accomplish this?

                again i ask: how does the text edit control (on mac) do it? that looks great!

                Pl45m4P M 2 Replies Last reply
                0
                • D davecotter

                  @mpergand said in Focus ring around tree/table views?:

                  treeView->setAttribute(Qt::WA_MacShowFocusRect);

                  note i tried this on the mac just to SEE it, and got exactly nothing. is there no way to accomplish this?

                  again i ask: how does the text edit control (on mac) do it? that looks great!

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #16

                  @davecotter

                  Qt::WA_MacShowFocusRect will create a QFocusFrame around the specific widget. If setting that flag doesnt work for you, you could try to build a QFocusFrame directly.

                  https://doc.qt.io/archives/qt-4.8/qfocusframe.html


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  1
                  • D davecotter

                    @mpergand said in Focus ring around tree/table views?:

                    treeView->setAttribute(Qt::WA_MacShowFocusRect);

                    note i tried this on the mac just to SEE it, and got exactly nothing. is there no way to accomplish this?

                    again i ask: how does the text edit control (on mac) do it? that looks great!

                    M Offline
                    M Offline
                    mpergand
                    wrote on last edited by
                    #17

                    @davecotter said in Focus ring around tree/table views?:

                    @mpergand said in Focus ring around tree/table views?:

                    treeView->setAttribute(Qt::WA_MacShowFocusRect);

                    note i tried this on the mac just to SEE it, and got exactly nothing. is there no way to accomplish this?

                    It works for me on MacOS 10.9, Qt 5.6
                    QFocusFrame doesn't work on Mac on the config above,
                    but works well on Linux (Ubuntu mate 18.04)

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      davecotter
                      wrote on last edited by
                      #18

                      i have tried to use Qt::WA_MacShowFocusRect on mac and see nothing. can you show a screen shot of what you see?

                      M 1 Reply Last reply
                      0
                      • D davecotter

                        i have tried to use Qt::WA_MacShowFocusRect on mac and see nothing. can you show a screen shot of what you see?

                        M Offline
                        M Offline
                        mpergand
                        wrote on last edited by
                        #19

                        @davecotter
                        Focus-Ring.png

                        edit=new QTextEdit;
                        edit->setAttribute(Qt::WA_MacShowFocusRect);
                        groupLayout->addWidget(edit);
                        
                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          davecotter
                          wrote on last edited by
                          #20

                          sorry, i wasn't talking about a text edit widget. that already works without my having to do anything.

                          i'm talking about putting a focus ring around a QTreeView and a QTableView.

                          and in that case it only shows the ring when the view has focus right? i don't have to manage that part myself, right?

                          M 1 Reply Last reply
                          0
                          • D davecotter

                            sorry, i wasn't talking about a text edit widget. that already works without my having to do anything.

                            i'm talking about putting a focus ring around a QTreeView and a QTableView.

                            and in that case it only shows the ring when the view has focus right? i don't have to manage that part myself, right?

                            M Offline
                            M Offline
                            mpergand
                            wrote on last edited by mpergand
                            #21

                            @davecotter
                            It's work with QTable/TreeView as well !
                            Focus-Ring2.png

                               QTreeView* edit=new QTreeView;
                               edit->setAttribute(Qt::WA_MacShowFocusRect);
                               groupLayout->addWidget(edit);
                               edit=new QTreeView;
                               edit->setAttribute(Qt::WA_MacShowFocusRect);
                               groupLayout->addWidget(edit);
                            

                            [EDIT]
                            For me, QTable and QTreeView have the focus ring by default (without setAttribute(Qt::WA_MacShowFocusRect);)
                            but for QTextEdit Qt::WA_MacShowFocusRect is needed.

                            1 Reply Last reply
                            2
                            • D Offline
                              D Offline
                              davecotter
                              wrote on last edited by
                              #22

                              huh, for me the text edit gets a ring automatically, and no matter what i do i can't get the tree or table view to get it.

                              note i'm setting it all up in Qt Designer, then programmatically adding the ring around tree/table views, to no avail.

                              M 1 Reply Last reply
                              0
                              • D davecotter

                                huh, for me the text edit gets a ring automatically, and no matter what i do i can't get the tree or table view to get it.

                                note i'm setting it all up in Qt Designer, then programmatically adding the ring around tree/table views, to no avail.

                                M Offline
                                M Offline
                                mpergand
                                wrote on last edited by mpergand
                                #23

                                @davecotter said in Focus ring around tree/table views?:

                                note i'm setting it all up in Qt Designer, then programmatically adding the ring around tree/table views, to no avail.

                                Check if the focus policy is not set to NoFocus.
                                On the code above, If I add :

                                edit->setFocusPolicy(Qt::NoFocus);
                                

                                Obviously the focus ring doesn't appear anymore.

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  davecotter
                                  wrote on last edited by
                                  #24

                                  Yes the views default to having "strongFocus". I have recreated the minimal project, which also does not show focus rings even with all the code correct as specified above.

                                  If anyone has a couple free minutes, please download and run this project, and tell me what's wrong?

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mpergand
                                    wrote on last edited by
                                    #25

                                    Your project works as expected for me.
                                    But I can't test above Qt 5.8 and MacOs 10.9.
                                    Maybe a bug in more recent Qt versions ?

                                    1 Reply Last reply
                                    0
                                    • D Offline
                                      D Offline
                                      davecotter
                                      wrote on last edited by davecotter
                                      #26

                                      well i am on macOS 10.14 and Qt 5.13.0

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        davecotter
                                        wrote on last edited by
                                        #27

                                        @mpergand said in Focus ring around tree/table views?:

                                        WA_MacShowFocusRect

                                        can anyone try on latest Qt?

                                        1 Reply Last reply
                                        0
                                        • D Offline
                                          D Offline
                                          davecotter
                                          wrote on last edited by
                                          #28

                                          @mpergand or anyone, can you reproduce the problem? that the focus ring is 1px no matter what? if you see CORRECT results (nice ring like around the search box) can you screen shot that and tell me what version of Qt you're using?

                                          i still can not for the life of me get this ring to look good

                                          M 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