Focus ring around tree/table views?
-
@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:
Table view has focus:
-
@davecotter
well that makes it easier:QTreeView:focus { border: 1px solid #6a6ea9; }
-
@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?:
Search bar does it correctly:
No ring around treeview:
No ring around table view:
should i be using
QFocusFrame
? -
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); -
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 ?
-
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
-
@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(); }
-
@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 ... -
@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.
-
@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!
-
@davecotter you're welcome 😉
strange I can confirm that, but the pixel size used to make a difference 🤔
-
@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!
-
Qt::WA_MacShowFocusRect
will create aQFocusFrame
around the specific widget. If setting that flag doesnt work for you, you could try to build aQFocusFrame
directly. -
@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) -
i have tried to use
Qt::WA_MacShowFocusRect
on mac and see nothing. can you show a screen shot of what you see? -
edit=new QTextEdit; edit->setAttribute(Qt::WA_MacShowFocusRect); groupLayout->addWidget(edit);
-
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?
-
@davecotter
It's work with QTable/TreeView as well !
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. -
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.
-
@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.