How to apply Hover styling when navigating QTreeView via the Keyboard
-
Hi all,
In my application I have a QMenu full of menu items, sub menu's etc.
One of my submenus, contains one of more menu items, and a QWidget.
The QWidget is in fact a QTreeView, which displays a limited view of some data in a tree.When I use the mouse to navigate the Menus, I get the change in background, according to which item
the mouse is currently over, ie the Hover item.
I even have this working in the TreeViewWidget which is attached as a Menu Item, by setting the stylesheetsetStyleSheet("QTreeView::item:hover" "{" "background: #555555;" "}");
However when I navigate the same menus via the keyboard,
I cannot get the Hover effect to work for the Items in the TreeView.So how can I programmatically tell the treeview that a specific QModelIndex should currently have the Hover status applied?
and thus it will trigger the drawing of that item as desired?My theory is to catch the down arrow key press event, when it is on the bottom menu item,
and then set the focus to the QTreeView Widget Item, and set the Top item in the TreeView to be Hovered.
( The QTreeView Widget item lives at the bottom of the menu in question )Thoughts?
-
@Jammin44fm If you navigate with the keyboard you do not move the cursor, so nothing is being hovered. But you can change the background of the selected items.
-
Ah yes, of course, thats makes a lot of sense.
I'll set the item as selected, and change the way i draw a selected item to match that of a hovered item.Thank you i think i was trying to overcomplicate things.
-