Focus ring around tree/table views?
-
@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.
-
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?
-
well i am on macOS 10.14 and Qt 5.13.0
-
@mpergand said in Focus ring around tree/table views?:
WA_MacShowFocusRect
can anyone try on latest Qt?
-
@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
-
if i embed the views inside a QFrame, with 3px borders, then draw the focus on the QFrames, that looks good. i can tab between all 3 items and the borders look good (if the wrong color).
but that leaves the wrong QObject with the focus. i need the tree/table views to have actual focus.
soi try to do this:
treeFrame->setFocusProxy(treeView);
tableFrame->setFocusProxy(tableView);then the edit text and tree frame look good, but the table view is back to looking all wrong again (1 pixel border)
good:
good:
bad:
why 1 pixel? the code is correct.
I've a new minimal project if some kind soul (who likes karaoke?) could take a look?
http://kjams.com/downloads/qfocustest.zipthanks
-dave