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
    #1

    when i click into a text edit in my window (search box) i get a nice focus ring, indicating where the keyboard has focus:

    0_1565219483408_Screen Shot 2019-08-07 at 4.11.16 PM.png
    this is exactly what i want.
    but i ALSO want it when the user clicks in the tree or table view, surrounding the view. but no focus ring is shown.

    note that the underlying QWidgets all have "strongFocus" as the focusPolicy, but that doesn't seem related. How can i get this lovely focus ring to appear around my other views?

    J.HilkJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      try:

      treeView->setAttribute(Qt::WA_MacShowFocusRect);
      
      1 Reply Last reply
      2
      • D davecotter

        when i click into a text edit in my window (search box) i get a nice focus ring, indicating where the keyboard has focus:

        0_1565219483408_Screen Shot 2019-08-07 at 4.11.16 PM.png
        this is exactly what i want.
        but i ALSO want it when the user clicks in the tree or table view, surrounding the view. but no focus ring is shown.

        note that the underlying QWidgets all have "strongFocus" as the focusPolicy, but that doesn't seem related. How can i get this lovely focus ring to appear around my other views?

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

        @davecotter
        as far as I know, the MacShowFocusRect that @mpergand suggested only works on Mac.

        So if you're looking for a more general approach, than take a look at the stylesheet example for a customized ListView

        https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qlistview

        QListView::item:selected is probably the selector you need


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

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

          QListView::item:selected

          well i'm looking for a ring around the entire view, not around an item, like this:

          Tree view has focus:
          0_1565247225366_Screen Shot 2019-08-07 at 11.53.13 PM.png

          Table view has focus:
          0_1565247257024_Screen Shot 2019-08-07 at 11.53.18 PM.png

          J.HilkJ 1 Reply Last reply
          0
          • D davecotter

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

            QListView::item:selected

            well i'm looking for a ring around the entire view, not around an item, like this:

            Tree view has focus:
            0_1565247225366_Screen Shot 2019-08-07 at 11.53.13 PM.png

            Table view has focus:
            0_1565247257024_Screen Shot 2019-08-07 at 11.53.18 PM.png

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

            @davecotter
            well that makes it easier:

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

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

              @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 1 Reply Last reply
              0
              • D Offline
                D Offline
                davecotter
                wrote on last edited by
                #7

                tried this and got exactly nothing:

                QFocusFrame *focus1P(new QFocusFrame(ui->sourcesList));
                focus1P->setWidget(ui->sourcesList);
                QFocusFrame *focus2P(new QFocusFrame(ui->tracksList));
                focus2P->setWidget(ui->tracksList);

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

                  It can't work because the border must be drawn above the widget.

                  As far as I know, it's only work on Mac with WA_MacShowFocusRect as I said earlier.

                  The possible solution would be to embed the view inside a QFrame with a 3 px margin.

                  The ultimate question should be : why do you want to implement a feature that is not standard except on Mac ?

                  1 Reply Last reply
                  0
                  • 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

                                          • Login

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