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

                                          • Login

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